confusion matrix

A confusion matrix breaks a classifier's predictions into four buckets — true positive, false positive, true negative, false negative — and every other classification metric covered on this site, from classifier-precision to recall to f1-score, is computed directly from those four numbers. A disease-screening program testing 1,000 patients, of whom 50 actually have the condition, might produce 45 true positives (sick patients correctly flagged), 5 false negatives (sick patients missed), 20 false positives (healthy patients wrongly flagged), and 930 true negatives (healthy patients correctly cleared) — four numbers that, once sorted, tell a far more complete story than any single score could on its own.

1,000 patients screened
50 actually sick, 950 actually healthy
TP: 45
actually sick, correctly flagged
FN: 5
actually sick, model MISSED them
FP: 20
actually healthy, wrongly flagged
TN: 930
actually healthy, correctly cleared
Every metric derives from these four numbers
accuracy 97.5% · precision 69% · recall 90%

That one worked example shows exactly why a single accuracy number can hide a model's real behavior. Overall accuracy here is (45 plus 930) divided by 1,000, or 97.5% — a number that sounds excellent in isolation. But precision is only 45 divided by 65 (the 45 true positives plus the 20 false positives), or about 69%, meaning roughly one in three patients flagged as sick is actually healthy; recall is 45 divided by 50, or 90%, meaning one in ten genuinely sick patients still gets missed. The 97.5% accuracy figure is dominated by the 930 healthy patients correctly cleared and says almost nothing about how the model handles the 50 patients who actually matter most — which is the general problem with accuracy on any dataset where one class vastly outnumbers the other, and the confusion matrix is what exposes it.

Specificity completes the picture that precision and recall leave out, by measuring performance on the negative class the same way recall measures it on the positive class. Specificity is true negatives divided by true negatives plus false positives — in the screening example, 930 divided by 950, or about 98% — answering "of everyone who's actually healthy, how many did the model correctly clear?" rather than anything about the sick patients. A model can have excellent recall and poor specificity (catches nearly every sick patient, but also wrongly flags a lot of healthy ones) or the reverse, and reading only precision and recall without checking specificity misses this axis entirely.

Which Mistake Is Worse Depends Entirely on the Domain same confusion matrix shape, very different real-world priorities Cancer screening Priority: recall > 95% Missing a real case is fatal. False alarms cost a follow-up test. Tolerates low precision Spam filtering Priority: precision > 99% Deleting a real email is worse than letting some spam through. Tolerates lower recall Fraud detection Priority: recall ~90% Missed fraud costs real money. False alarms cost a support call. Leans recall, not absolute Self-driving obstacle detection Priority: recall ~100% Missing a pedestrian is catastrophic. A false brake is just annoying. Extreme recall priority Criminal conviction Priority: precision Convicting an innocent person is worse than one going free. Extreme precision priority All five share the exact same matrix shape — TP, FP, FN, TN — only which quadrant hurts more differs. The matrix is the same for every classifier — which cell is expensive to get wrong is a business decision, not a math one.

Moving the decision threshold slides every cell in the matrix at once, which is why precision and recall move in opposite directions from the same lever. Requiring higher model confidence before predicting "positive" shrinks the positive-prediction count, which tends to raise precision (fewer borderline false positives sneak through) while lowering recall (some real positives that weren't confident enough get reclassified as negative); lowering the threshold does the exact reverse. This single mechanism is the reason precision and recall are reported together rather than optimized independently — pushing either one toward 1.0 by moving the threshold alone always costs something on the other side of the same matrix.

The confusion matrix is the ground truth every other classification metric is a summary of, which is also exactly its limitation: a single score, whether it's accuracy, precision, recall, or F1, is always a lossy compression of the full four-number picture, chosen to highlight whichever failure mode matters most for a given domain — and the only way to know whether that choice was the right one is to look at the matrix underneath it and ask what got traded away to produce that one number.

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account