Confusion Matrix

less than 1 minute read

Confusion Matrix

from sklearn.metrics import confusion_matrix
y_true = [2, 0, 2, 2, 0, 1]
y_pred = [0, 0, 2, 2, 0, 2]
confusion_matrix(y_true, y_pred)

y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]
confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])
# fig = plt.figure()
# cax = ax.matshow(cm)
# plt.show()

array([[2, 0, 0],
       [0, 0, 1],
       [1, 0, 2]])

confusion matrix