Skip to content

Instantly share code, notes, and snippets.

@emmagrimaldi
Created September 22, 2018 21:06
Show Gist options
  • Select an option

  • Save emmagrimaldi/707915f7472e9883ad75450b36b87a00 to your computer and use it in GitHub Desktop.

Select an option

Save emmagrimaldi/707915f7472e9883ad75450b36b87a00 to your computer and use it in GitHub Desktop.
from sklearn.metrics import confusion_matrix
def conf_matrix(model, X_test):
y_pred = model.predict(X_test) # calculate predictions
cm = confusion_matrix(y_test, y_pred) # defining the confusion matrix
tn, fp, fn, tp = cm.ravel() # assigning the elements of the confusion matrix to variables
print(f"True Negatives: {tn}") # print those variables
print(f"False Positives: {fp}")
print(f"False Negatives: {fn}")
print(f"True Positives: {tp}") # return the confusion matrix as dataframe
return pd.DataFrame(cm,
columns = ['Pred Deep Philosophy','Pred Shower Thoughts'],
index = ['Act Deep Philosphy', 'Act Shower Thoughts'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment