Confusion Matrix
A confusion matrix is a table that summarizes every classifier prediction against every actual class, making it easy to see which categories the model confuses.
Key takeaways
- Confusion matrices tabulate predictions against actual classes to reveal specific error patterns.
- Diagonal cells are correct predictions; off-diagonal cells show what the model confuses.
- They are essential for understanding failure modes that accuracy alone hides.
A confusion matrix is a table with predicted classes as one axis and actual classes as the other. Each cell counts how many examples fell into that predicted-actual pair. The diagonal cells are correct predictions; off-diagonal cells reveal specific confusions.
That tabular layout is deceptively powerful. Accuracy alone says whether the model is right overall, but the confusion matrix shows exactly where it fails. A medical model that confuses benign and malignant tumors has the same accuracy cost as one that confuses two benign subtypes, but the real-world consequences are completely different. The matrix makes that distinction visible.
Think of it like this. Think of a grade sheet that does not just show the final score, but lists which question types the student got wrong. The total mark tells you they passed; the breakdown tells you what to study next.
How it works
For each prediction, the actual label and predicted label determine which cell increments. True positives, true negatives, false positives, and false negatives are read directly from the matrix. Multi-class matrices scale the same idea to more than two labels, sometimes with row or column normalization to compare relative error rates.
Common mistakes
"Accuracy is enough." Accuracy hides which classes are failing. "A diagonal matrix means the model is perfect." Some errors are more costly than others. "Confusion only applies to classification." It also applies to segmentation, detection, and information retrieval with adapted layouts.
Trade-offs
Transparent and easy to compute, but becomes harder to interpret with many classes. Normalized or visualized versions help, though they sacrifice exact counts for readability.