The Confusion Matrix: Why Accuracy Deceives

A 2x2 table of what a classifier got right and wrong, broken out by type. Every classification metric is derived from its four cells, and it shows why one number is never enough.

On this page

A single accuracy number tells you how often a classifier is right. It hides the far more useful information: how it is wrong. The confusion matrix is the table that puts the how back in, and once you can read one, most classification metrics become obvious rather than memorized.

The table

For a two-class problem it is a 2x2 grid. Rows are the true label, columns are what the model predicted.

                  Predicted Positive   Predicted Negative
Actual Positive        TP  (85)             FN  (15)
Actual Negative        FP  (30)             TN  (870)

Those are the same four counts from precision, recall, and accuracy: true positives, false negatives, false positives, true negatives. The diagonal (TP, TN) is where the model was right. The off-diagonal (FP, FN) is where it was wrong — and the two off-diagonal cells are usually two completely different problems.

Why one number cannot capture this

Take the table above. 85 + 870 = 955 correct out of 1000, so accuracy is 95.5%. Sounds strong.

Now read the cells. Of 100 actual positives, the model caught 85 and missed 15 (recall 0.85). Of the 115 it flagged, 30 were wrong (precision 0.74). Whether this model is good depends entirely on which mistake hurts: the 15 misses or the 30 false alarms. The accuracy number erased that distinction. The matrix preserved it.

The deception gets worse with imbalance. Flip the problem so positives are rare — 10 actual positives out of 1000. A model that predicts “negative” every time produces:

                  Predicted Positive   Predicted Negative
Actual Positive         0                    10
Actual Negative         0                    990

Accuracy is 99%. Recall is 0. The matrix shows the empty positive column instantly; accuracy hides it behind a big number. This is the single most important reason to look at the matrix first.

The rates you read off it

Every derived metric is a ratio of cells, read along a row or column:

  • Recall / sensitivity / true positive rate = TP / (TP + FN) — across the actual-positive row. Of the real positives, how many were caught.
  • Specificity / true negative rate = TN / (TN + FP) — across the actual-negative row. Of the real negatives, how many were correctly cleared.
  • Precision = TP / (TP + FP) — down the predicted-positive column. Of the flags raised, how many were right.
  • False positive rate = FP / (FP + TN) = 1 − specificity. The rate of false alarms among true negatives. This is the x-axis of an ROC curve.

Reading by row versus by column is the whole trick. Recall and specificity condition on the truth (the rows). Precision conditions on the prediction (a column). That is why precision moves when the class balance changes even though the model has not — a point that surprises people until they see it on the grid.

More than two classes

For N classes the matrix is N x N. The diagonal is correct predictions; every off-diagonal cell tells you a specific confusion — how often “5” was read as “6”, how often “cat” was called “dog”. This is where the matrix earns its name, and it is diagnostic gold: the biggest off-diagonal cells point straight at which pairs your model cannot tell apart, which is exactly where labeling effort or features should go.

To collapse a multi-class matrix to one number you compute per-class precision and recall and average. Macro-average treats every class equally (good when rare classes matter). Micro-average pools all counts first, so it is dominated by frequent classes. Choosing between them is another decision the raw accuracy number would have made silently and probably wrongly.

Use it as a first move

Before trusting any scalar metric, print the matrix. It takes one line of code and it answers questions the scalar cannot: Are the errors symmetric or lopsided? Is one class being ignored entirely? Which pairs get confused? Almost every “our accuracy is high but the model feels broken” story ends at a confusion matrix that was never looked at.

What to remember

  • The matrix breaks predictions into TP, FP, FN, TN, separating the two kinds of error that a single accuracy number fuses together.
  • Under class imbalance, high accuracy can coexist with zero recall — the empty positive column is obvious in the matrix and invisible in the scalar.
  • Recall and specificity read across truth rows; precision reads down a prediction column — which is why precision shifts with class balance.
  • For N classes, the largest off-diagonal cells name exactly which categories the model confuses.
  • Look at the matrix before trusting any derived metric.

Next: ROC and AUC