difficulty 1/5
Confusion matrix
A table counting how a classifier's predictions line up against the truth — correct and incorrect, broken down by which class was predicted and which was actual.
Intuition
A single accuracy number tells you how often a classifier is right. It does not tell you how it is wrong, and for most real problems that is the part that matters. Missing a fraud is not the same kind of mistake as flagging an honest transaction, even though both count identically against accuracy [2, Accuracy].
The confusion matrix keeps the mistakes separate. Every prediction lands in one cell, and the shape of the table tells you which error the model prefers to make [1, definition].
Almost every other classification metric on this site is a ratio computed from these four cells. Learn the table and the rest follow [2, Recall · False positive rate · Precision].
Formal definition
How it works
Where it's used
Why & when
Worked example
Pitfalls
Check yourself
3 questions
The questions on this page come with access. They are graded on the server, so the answers stay there until you have given yours.
On the cheat sheet: Classification metrics →
Sources
- scikit-learn — sklearn.metrics.confusion_matrixdocs · retrieved 2026-08-30https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html
- Machine Learning Crash Course — Classification: accuracy, recall, precision, and related metricscourse · retrieved 2026-10-04https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall
- Machine Learning Crash Course — Thresholds and the confusion matrixcourse · retrieved 2026-10-06https://developers.google.com/machine-learning/crash-course/classification/thresholding
- Introduction to Information Retrieval (2008)bookhttps://nlp.stanford.edu/IR-book/html/htmledition/irbook.html