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.
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.
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.