Answers for "plot_confusion_matrix sklearn example"

2

sklearn plot confusion matrix

import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix, plot_confusion_matrix

clf = # define your classifier (Decision Tree, Random Forest etc.)
clf.fit(X, y) # fit your classifier

# make predictions with your classifier
y_pred = clf.predict(X) 
        
# optional: get true negative (tn), false positive (fp)
# false negative (fn) and true positive (tp) from confusion matrix
M = confusion_matrix(y, y_pred)
tn, fp, fn, tp = M.ravel() 

# plotting the confusion matrix
plot_confusion_matrix(clf, X, y)
plt.show()
Posted by: Guest on May-14-2021
0

confusion matrix with labels sklearn

import pandas as pd
y_true = pd.Series([2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2])
y_pred = pd.Series([0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2])

pd.crosstab(y_true, y_pred, rownames=['True'], colnames=['Predicted'], margins=True)
Posted by: Guest on March-07-2021

Code answers related to "plot_confusion_matrix sklearn example"

Python Answers by Framework

Browse Popular Code Answers by Language