title: Why is my accuracy_score metric incorrect? scikit learn
body: <p>I have <em>somewhat</em> working code, which is giving me trouble. I seem to get an almost random accuracy_score metric, whereas my printout of predicted values suggests otherwise. I was following <a href="https://www.dataquest.io/blog/sci-kit-learn-tutorial/" rel="nofollow noreferrer">this</a> tutorial online and here is what I have written so far:</p>
  <pre><code>import os
  import pandas as pd
  from sklearn.preprocessing import LabelEncoder
  from sklearn.model_selection import train_test_split
  from sklearn.naive_bayes import GaussianNB
  from sklearn.metrics import accuracy_score, confusion_matrix
  
  adult_train = pd.read_csv(os.path.expanduser(&quot;~/Desktop/&quot;) + &quot;adult_train_srt.csv&quot;, sep=',')
  print(adult_train.head(100))
  
  le = LabelEncoder()
  adult_train['age'] = le.fit_transform(adult_train['age'])
  adult_train['workclass'] = le.fit_transform(adult_train['workclass'].astype(str))
  adult_train['education'] = le.fit_transform(adult_train['education'].astype(str))
  adult_train['occupation'] = le.fit_transform(adult_train['occupation'].astype(str))
  adult_train['race'] = le.fit_transform(adult_train['race'].astype(str))
  adult_train['sex'] = le.fit_transform(adult_train['sex'].astype(str))
  adult_train['hours_per_week'] = le.fit_transform(adult_train['hours_per_week'])
  adult_train['native_country'] = le.fit_transform(adult_train['native_country'].astype(str))
  adult_train['classs'] = le.fit_transform(adult_train['classs'].astype(str))
  
  cols = [col for col in adult_train.columns if col not in ['classs']]
  data = adult_train[cols]
  target = adult_train['classs']
  
  data_train, data_test, target_train, target_test = train_test_split(data, target, test_size = 0.1) #, random_state = 42)
  
  gnb = GaussianNB()
  pred = gnb.fit(data_train, target_train).predict(data_test)
  pred_gnb = gnb.predict(data_test)
  print(pred_gnb)
  
  print(&quot;Naive-Bayes accuracy: (TN + TP / ALL) &quot;, accuracy_score(pred_gnb, target_test)) #normalize = True
  print(&quot;&quot;&quot;Confusion matrix:
  TN - FP
  FN - TP
  Guessed:
  0s +, 1s -
  0s -, 1s +
  &quot;&quot;&quot;)
  print(confusion_matrix(target_test, pred_gnb))
  
  Prediction = pd.DataFrame({'Prediction':pred_gnb})
  
  result = pd.concat([adult_train, Prediction], axis=1)
  print(result.head(10))
  </code></pre>
  <p>I am at a loss, I have no way of understanding whether or not my dataframe concatenation is working or if the accuracy_score metric is solving something else, because I get outputs like so:
  <a href="https://i.stack.imgur.com/NbD1e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NbD1e.png" alt="enter image description here" /></a></p>
  <p>This particular instance it is saying there are 7 true negatives (OK), 1 false positive (???), 2 false negatives (O.K), and 0 true positives (???, but there was one guessed correct?). The [classs] column is what the [Prediction] columnn is guessing.</p>