Worked examples — Confusion matrix interpretation
This is the "throw everything at it" companion to the parent note. There we derived the metrics. Here we stress-test them: every degenerate matrix, every extreme threshold, every sign of imbalance, and the word problems that trip people up. The rule of the page: guess the answer before you read the solution. If your guess is wrong, that cell of the scenario matrix is where your intuition needs repair.
Before we start, one shared picture we will point back to all page long.

The 2×2 grid: rows are reality (top row = actually positive, bottom = actually negative), columns are the model's guess (left = predicted positive, right = predicted negative). The green diagonal (TP, TN) is "the model was right." The coral off-diagonal (FN, FP) is "the model was wrong." Keep this grid in your head — every example below just fills these four boxes with different numbers, and each example tells you which box it is pushing to an extreme so you can locate it on this same picture.
The four metrics in one place (defined before we use them)
Everything below is built from four ratios. Read each as "correct count ÷ the group it belongs to." We anchor each denominator to a row or column of the grid above.
For a fuller treatment of these four ratios see Precision and Recall.
The scenario matrix
Here is the full menu of cases a confusion-matrix problem can be. Each worked example below is tagged with the cell(s) it covers, so you can check nothing is missed.
| # | Case class | What is extreme | Which example |
|---|---|---|---|
| A | Perfect model | FP = FN = 0 | Ex 1 |
| B | Degenerate: predict-all-negative | TP = FP = 0 | Ex 2 |
| C | Degenerate: predict-all-positive | TN = FN = 0 | Ex 3 |
| D | Severe class imbalance | one row hugely bigger | Ex 2, Ex 4 |
| E | Precision–recall tension | high P, low R (and reverse) | Ex 4, Ex 5 |
| F | Threshold sweep (limiting values) | threshold → 0 and → 1 | Ex 5 (+figure) |
| G | Zero-denominator traps | TP+FP = 0 or TP+FN = 0 | Ex 6 |
| H | Real-world word problem | translate story → matrix | Ex 7 |
| I | Multi-class per-class extraction | one-vs-rest slicing | Ex 8 |
| J | Exam twist: back-solve from metrics | given metrics, find cells | Ex 9 |
Prerequisites you may want open: Precision and Recall, Binary Classification Thresholds, Class Imbalance Handling, Multi-class Classification Metrics.
Example 1 — The perfect model (Case A)
Forecast: guess accuracy, precision, recall, specificity before reading. (Everyone gets this one — it is the anchor.)
-
Fill the grid. On the shared grid figure, every sample lands on the green diagonal: all positives in the top-left box (TP), all negatives in the bottom-right box (TN). Why this step? "Zero mistakes" means both coral off-diagonal boxes (FN, FP) are empty — the matrix is purely diagonal, the definition of a perfect classifier.
-
Compute metrics. Why this step? Every metric is a ratio whose numerator equals its denominator when there are no errors, so all equal exactly .
Verify: F1 harmonic mean of two s is . Diagonal-only matrix ⇒ every metric maxes out. Sanity: no metric can exceed , and we hit the ceiling — consistent.
Example 2 — Predict "all negative" on imbalanced data (Cases B, D)
Forecast: accuracy will be high. Now guess recall — is it high or zero?
-
Fill the grid. On the shared grid, everything lands in the right column (predicted negative). Both left-column boxes empty out. Why this step? "Predicted positive" is the left column of our grid — if the model never says positive, that whole column is zero, which zeroes TP and FP.
-
Accuracy. Why this step? The 980 legit emails are all correctly called negative; accuracy rewards this bulk and ignores the tiny positive class.
-
Recall. Why this step? Of the 20 real spam, the model caught none. Recall — the top-row view over actual positives — collapses to zero.
-
Precision. The denominator — undefined. See Example 6 for how to handle this; conventionally reported as or
NaN.
Verify: accuracy vs recall — the exact "class-blind accuracy" trap from the parent's Mistake 1. A useless model scoring 98% proves accuracy alone is meaningless under imbalance. See Class Imbalance Handling.
Example 3 — Predict "all positive" (Case C)
Forecast: recall will be perfect. Guess what specificity does.
-
Fill the grid. On the shared grid, everything lands in the left column (predicted positive), so the right column empties out. Why this step? All 20 real spam are (accidentally) caught → TP , FN . All 980 legit are wrongly flagged → FP , TN .
-
Recall. Why this step? Catching everything guarantees you catch all positives — recall is trivially perfect. This is the "crying wolf" limit.
-
Precision. Why this step? Of 1000 "spam" alarms, only 20 were real. Precision — the left-column view over predicted positives — is dismal.
-
Specificity. Why this step? Of 980 real negatives, zero were correctly cleared. Perfect recall bought total loss of specificity.
Verify: compare with Ex 2 — Ex 2 has recall /specificity ; Ex 3 has recall /specificity . The two degenerate extremes sit on opposite ends of the same seesaw. That seesaw is the ROC Curve and AUC itself.
Example 4 — A realistic imbalanced model (Cases D, E)
Forecast: accuracy near 98%. But guess precision — will it be high or low? (Watch the FP.)
-
Sanity-fill the grid. Top row (actual positives) ✓, bottom row (actual negatives) ✓, total ✓. Why this step? Always check the row sums match the stated class counts before computing anything.
-
Accuracy. Why this step? Sum the green diagonal (TP TN, the correct calls) over all 10000 predictions — accuracy is the plain "fraction right," and here the enormous TN dominates it into looking excellent.
-
Precision. Why this step? 270 fraud alarms (the left column), only 70 real. Even a "good-looking" 97.7% model flags roughly 3 false alarms for every real fraud — precision exposes it.
-
Recall. Why this step? Of the 100 real frauds (the top row, TP FN), we caught 70 — recall reads the row over actual positives and reveals that 30 frauds slipped through.
-
Specificity. Why this step? High specificity because the huge negative bottom row swamps the 200 false alarms — a warning that specificity looks flattering under imbalance, unlike precision.
-
F1 (using the definition we set up above, with precision, recall). Why this step? Using the closed form avoids rounding and first. sits low, between the low precision and moderate recall — the honest summary.
Verify: harmonic-mean check: ✓, matches the closed form. Accuracy hid a model that is right only about 26% of the time when it shouts "fraud."
Example 5 — Threshold sweep: the limiting values (Cases E, F)
Forecast: at (predict positive almost never) and (predict positive always), what are and ?
The scores (positive samples marked ●, negatives ○), sorted high→low:

How to read this figure. The horizontal axis is the model's output score (from on the left to on the right). Each dot is one sample placed at its score; lavender dots are actual positives (marked above them), butter dots are actual negatives (marked ). A threshold is a vertical line: everything to the right of it (score ) is predicted positive, everything to the left predicted negative. The two dashed lines show the two thresholds we test below. The top arrow reminds you that sliding leftward admits more samples as positive — this is the single knob that trades recall for precision.
-
Threshold (predict positive if score ). No dot is to the right of the far-right edge — nobody clears it. Why this step? This is the right edge of the sweep — the same degenerate "predict-all-negative" state as Ex 2. Recall starts at .
-
Threshold (the coral dashed line; score → positive). The three dots to its right are two lavender (●) and one butter (○). Why this step? Sliding the line left lets more samples through — recall rises, but the first negative sneaks in, so precision drops below . This is the P–R tension made mechanical.
-
Threshold (the mint dashed line). Six dots now sit to its right: four ● and two ○. Why this step? Recall keeps climbing as we admit more positives; precision plateaus because we admitted one more of each class.
-
Threshold (predict positive always). Every dot is to the right. Why this step? The left edge — the same "predict-all-positive" state as Ex 3. Recall maxes at ; precision falls to the base rate .
Verify: recall is monotonically non-decreasing as drops () — correct, lowering a threshold can never lose a caught positive. Precision at equals the positive base rate — the classic limiting value. See Binary Classification Thresholds.
Example 6 — The zero-denominator traps (Case G)
Forecast: which metric blows up in each case, and what is the sensible convention?
-
Case (a): no actual positives. All 50 are negative and all are called negative: . Why this step? Recall asks "of the real positives, how many caught?" — but there are no real positives (top row is empty), so the question is meaningless. Convention: report recall as or
NaN(nothing was there to miss). Specificity is fine: . -
Case (b): never predict positive, on a batch that has positives. Take a concrete batch of 50: suppose 8 are truly positive and 42 truly negative — these two numbers come from the batch's ground truth, not from us; we just need some positives present to expose the trap. Since the model never says positive, the entire left column is zero: , and every real positive is missed so , every real negative is (passively) correct so . Why this step? Precision asks "of your positive calls, how many right?" — but you made no positive calls (left column empty), so the denominator vanishes. The specific 8-and-42 split is irrelevant to the trap; any batch with at least one positive triggers it. Convention: precision (you contributed no true positives) or
NaN. -
F1 with a zero. If either or is , then Why this step? The harmonic mean rightly punishes: being perfect on one axis while zero on the other yields a zero — never .
Verify: the "predict-all-negative" from Ex 2 is , consistent with the rule here. Zero denominators are always a degenerate matrix, never a bug — name the missing group and move on.
Example 7 — Word problem: translate the story (Case H)
Forecast: the two questions map to two named metrics — which ones?
-
Identify positive class. Positive = "bag contains prohibited item" (the thing we want to detect). Why this step? Always define positive as the event of interest; every metric's meaning flips if you mislabel it.
-
Extract the four counts from the sentence.
- "correctly stopped 45 of the 50" → TP , FN .
- "also stopped 300 harmless" → FP .
- remaining bags: total , threats , so harmless ; correctly passed harmless → TN . Why this step? "Stopped" = predicted positive (left column); "harmless" = actually negative (bottom row). Cross the story's verbs with reality/prediction to fill the grid.
-
"How trustworthy is an alarm?" → precision. Why this step? An "alarm" is a positive prediction (the left column); "how often is it right" is precision by definition.
-
"What fraction of threats slip through?" → miss rate . Why this step? "Slip through" = real positive predicted negative = FN out of all real positives = the complement of recall.
Verify: counts sum to ✓. Only 13% of alarms are real threats but only 10% of threats escape — a classic high-recall / low-precision security posture (see Cost-Sensitive Learning for why that trade is deliberate).
Example 8 — Multi-class: slice out one class (Case I)
Forecast: dog's TP is the (dog, dog) diagonal . Guess FP and FN before computing.
-
One-vs-rest for dog. Collapse the multi-class table back into our 2×2 grid by treating "dog" as positive and everything else as negative.
- (the diagonal entry).
- (dog row, off-diagonal — real dogs called something else).
- (dog column, off-diagonal — others called dog). Why this step? Row-minus-diagonal = things of this class we missed; column-minus-diagonal = things we wrongly assigned here. This is the parent's per-class recipe, mapped onto the same top-row / left-column reading we have used all page.
-
Dog precision and recall. Why this step? Same two ratios as always, now on the collapsed dog-vs-rest grid: precision over the dog column, recall over the dog row.
-
Micro-averaged precision — pool all classes' TP and FP first, then divide once. Total TP . Total off-diagonal (every misclassification is somebody's FP) . Why this step? Micro pools counts first, so it weights by how many samples each class has. Macro-averaging (see Multi-class Classification Metrics) would instead average the three per-class precisions equally, ignoring class size.
Verify: dog recall = row ✓. Micro precision equals overall accuracy — in single-label multi-class every FP is another class's FN, so micro-precision = micro-recall = accuracy, a useful identity.
Example 9 — Exam twist: back-solve the matrix (Case J)
Forecast: you can get TP straight from recall. Try it before reading.
-
TP from recall. Recall , so Why this step? Recall's denominator is the known count of actual positives (the top row, ), so it pins TP immediately.
-
FN from the positive row. Actual positives TP FN, so Why this step? The top row must sum to the given 200 actual positives, so whatever TP does not account for is FN.
-
FP from precision. Precision , so Why this step? Precision links TP to the predicted-positive total (the left column); knowing TP lets us solve for FP algebraically.
-
TN from the negative row. Actual negatives FP TN , so Why this step? The bottom row must sum to the given 800 actual negatives, so whatever is not a false alarm is a true negative.
-
Accuracy. Why this step? With all four cells recovered, accuracy is the plain diagonal-over-total from its definition.
Verify: back-check both given metrics from the reconstructed cells — ✓ and ✓. Full matrix sums to ✓. When they hand you metrics, invert them via their known denominators (see Model Selection Criteria).
Recall Self-test (reveal after guessing)
Predict-all-negative on imbalanced data: what is recall? ::: Exactly — you catch no positives, no matter how high accuracy climbs. Which metric has an undefined denominator when the model never predicts positive? ::: Precision (denominator ). As you lower the decision threshold, which of precision/recall is guaranteed non-decreasing? ::: Recall — admitting more positives can never lose a caught one. In single-label multi-class, micro-precision equals which familiar scalar? ::: Overall accuracy. Given precision, recall, and the actual-positive count, which cell do you solve for first? ::: TP, directly from recall (actual positives).