Evaluating Classification: The Confusion Matrix
The confusion matrix provides a complete picture of a classifier's performance by counting correct and incorrect predictions for every combination of true and predicted class.
Structure of the Confusion Matrix
For binary classification, the matrix has four cells: True Positives (TP), False Positives (FP), True Negatives (TN), and False Negatives (FN). Every derived metric — accuracy, precision, recall, F1 — comes from these four numbers.
Reading the Matrix
Rows represent actual classes; columns represent predicted classes. Correct predictions sit on the diagonal; off-diagonal cells are errors. A model that only makes errors in one direction (many FP or many FN) reveals a systematic bias you can address with threshold or weight adjustments.
Computing the Confusion Matrix
Multi-class Confusion Matrices
For K classes, the confusion matrix is K\u00d7K. The diagonal still represents correct predictions; each off-diagonal cell (i, j) counts examples of class i predicted as class j.
Interpreting Multi-class Errors
In multi-class problems, confusion matrices reveal which classes are most often confused with each other. If classes 2 and 3 are frequently swapped, they may require better feature engineering or dedicated post-processing to disambiguate.