Introduction
Evaluate the model we developed while performing research for either machine learning or deep learning projects is crucial. The best technique to see if the predicted value is well-classified is to use a confusion matrix. The confusion matrix function in the sklearn package, however, has a different interpretation than the one we usually find on other websites.
Compare WIKI with SKLEARN
In wiki page, we can see that each row of the matrix represents the instances in an actual class (ground truth) while each column represents the instances in a predicted class. But in sklearn confusion_matrix()
function, each row of the matrix represents the instances in an predicted class while each column represents the instances in a actual class.
from sklearn import metrics
y_true = ["cat", "dog", "cat", "cat", "dog", "penguin"]
y_pred = ["dog", "dog", "cat", "cat", "dog", "cat"]
metrics.confusion_matrix(y_true, y_pred, labels=["cat", "dog", "penguin"])
This will return
array([[2, 1, 0],
[0, 2, 0],
[1, 0, 0]], dtype=int64)
Conclusion
A confusion matrix is a two-row, two-column table in predictive analytics that provides the value of false positives, false negatives, true positives, and true negatives. This enables for more in-depth analysis than simply the fraction of right classifications, such as accuracy, f1, precision, and recall scores.