The table of what a classifier got right and wrong, class by class.A confusion matrix is a specific table layout that allows visualization of the performance of a supervised learning algorithm, typically a classifier. Each row of the matrix represents the instances in an actual class, while each column represents the instances in a predicted class (or vice versa). The name stems from the fact that it makes it easy to see if the system is confusing two classes (i.e., commonly mislabeling one as another).
The term was popularized in the field of machine learning in the 1960s, though the concept of a contingency table in statistics predates it. The exact origin is unclear.
For a classification problem with N classes, the matrix is N×N. The diagonal cells show the number of correct predictions for each class, while off-diagonal cells show misclassifications. From this table, one can derive metrics like accuracy, precision, recall, and F1-score. For binary classification, the matrix is 2×2 with entries typically called true positive, false positive, true negative, and false negative.
Used in evaluating and comparing classifiers in fields like medical diagnostics, spam detection, and image recognition, where understanding the types of errors matters more than overall accuracy.
A confusion matrix can be used to compute the Matthews correlation coefficient, which is a single metric that summarizes the entire matrix and is often more informative than accuracy for imbalanced datasets.








