Exercises — Confusion matrix interpretation
This is the practice ground for Confusion matrix interpretation. Every problem states its numbers cleanly, then hides a full worked solution inside a collapsible callout so you can self-test. Levels rise from "can you name the cell?" (L1) to "can you design a metric for a business goal?" (L5).

Reminder of the four formulas you will reach for (all are ratios of the counts above):
Level 1 — Recognition
Exercise 1.1
A model is evaluated. For one test sample the true label is Positive and the model predicted Negative. Name this cell of the confusion matrix and its classical error name.
Recall Solution
WHAT: True = Positive, Predicted = Negative → we missed a real positive. CELL: False Negative (FN). CLASSICAL NAME: Type II error (a "miss"). PICTURE: In the confusion-matrix grid above (Figure 1), rows are reality and columns are predictions; "Actual Pos, Predicted Neg" is the top-right cell.
Exercise 1.2
Given the confusion matrix below, read off TP, FN, FP, TN directly.
Recall Solution
WHAT each number means (read row = reality, column = prediction):
- — actual pos, predicted pos.
- — actual pos, predicted neg (row-1 off-diagonal).
- — actual neg, predicted pos (row-2, left column).
- — actual neg, predicted neg. CHECK: Total samples. Diagonal are the correct ones.
Level 2 — Application
Exercise 2.1
Using the matrix from Exercise 1.2 (), compute Accuracy, Precision, Recall, and Specificity.
Recall Solution
First, the denominators are all non-zero (, , ), so every metric is well-defined here. Accuracy — fraction of all predictions correct: Precision — of everything I called positive, how many were right? Denominator is predicted positives : Recall — of every actual positive, how many did I catch? Denominator is actual positives : Specificity — of every actual negative, how many did I correctly reject? Denominator :
Exercise 2.2
For the same matrix, compute the -score two ways (from precision & recall, and from raw counts) and derive why the raw-count shortcut equals the harmonic mean.
Recall Solution
Way 1 — harmonic mean of and . Keep and as exact fractions to avoid rounding drift, then plug into the harmonic mean: (If instead you round early — , — you get . Same value, but note these decimals are approximations; the exact fraction is the honest answer.) Way 2 — raw-count shortcut : WHY they match (derived here, step by step). Start from the harmonic-mean definition of and substitute , : WHAT we did: flipped each fraction (, likewise for ). WHY the harmonic form: the arithmetic mean is too forgiving — if but it reports ; the harmonic mean drags the score toward the smaller value, so both must be high. Now add the two fractions over the common denominator : WHAT we did: combined the numerators, then multiplied top and bottom by to clear the nested fraction. That last expression is exactly the shortcut — so the two forms are algebraically identical, not a coincidence. Both give the exact value .
Level 3 — Analysis
Exercise 3.1
A spam filter processes 10,000 emails. Only 200 are truly spam. The model flags 180 spam correctly, misses 20, and wrongly flags 300 legitimate emails as spam. Build the confusion matrix, then explain why its 96.8% accuracy is misleading.
Recall Solution
Fill the counts. Actual spam , actual legit .
- (spam caught), (spam missed).
- (legit flagged), (legit passed).
Accuracy: . Precision: . Recall: . WHY accuracy misleads: 98% of emails are legit, so a model that just passes almost everything scores high on accuracy automatically — the huge dominates. But precision is only 37.5%: nearly two-thirds of things sent to the spam folder are actually legitimate. Accuracy is class-blind; the imbalance hides the real cost. See Class Imbalance Handling.
Exercise 3.2
Same spam data. The team retunes the threshold (see Binary Classification Thresholds) so it now catches all 200 spam () but flags 1200 legit emails (). Did the model get better? Compare recall, precision, and specificity before vs after.
Recall Solution
New counts: .
| Metric | Before | After |
|---|---|---|
| Recall | ||
| Precision | ||
| Specificity |
Interpretation: Recall rose to a perfect — every spam caught. But precision collapsed to , and specificity dropped. This is the classic precision–recall trade-off: pushing the threshold to catch more positives sweeps in more false alarms. "Better" depends on cost — for a spam filter, deleting real email (low precision) is worse than letting some spam through, so the "after" model is arguably worse. See Precision and Recall.
Level 4 — Synthesis
Exercise 4.1
A 3-class classifier (cat, dog, bird) produces:
Compute per-class precision and recall for Dog, then compute the macro-averaged recall across all three classes. (Total samples .)
Recall Solution
Dog metrics — treat "Dog" as the positive class:
- (diagonal).
- row-2 off-diagonal .
- column-2 off-diagonal .
Recall for each class (diagonal ÷ row sum):
- Cat: row sum , recall .
- Dog: .
- Bird: row sum , recall .
Macro recall — average the per-class recalls, each weighted equally: See Multi-class Classification Metrics.
Exercise 4.2
For the same 3-class matrix, compute the micro-averaged recall and explain why it here equals overall accuracy.
Recall Solution
Micro pooling — add up all class-wise and first, then divide once:
- diagonal .
- all off-diagonal in each row (every misclassified sample is some class's FN) . Overall accuracy . WHY equal: in single-label multi-class, every sample is exactly one class's positive. Summed = all correct = diagonal, and = all samples. So micro-recall reduces to accuracy. (Note macro also coincidentally matches here only because every row sum is 50 — with imbalanced rows they'd differ.)
Level 5 — Mastery
Exercise 5.1
A cancer screen sees 1000 patients, 40 truly have cancer. A miss (FN) costs 100 units (a lethal error); a false alarm (FP) costs 1 unit (an extra biopsy). Model A: . Model B: . First compute each model's accuracy (to see the "same-looking" region), then decide which model is better using total cost, and separately by . Do the two criteria agree?
Recall Solution
First, accuracies — this is the "same-looking region." Both totals are :
- Model A: .
- Model B: .
So A actually looks far better on accuracy ( vs ) — a student glancing at accuracy would pick A immediately. That is exactly the trap; let the cost and tell a different story.
Total cost :
- Model A: .
- Model B: . → Model B is cheaper (better) because it slashes the deadly misses, and each avoided miss is worth 100 cheap biopsies.
:
- Model A: .
- Model B: . → prefers Model A.
They DISAGREE — and so does accuracy. Accuracy and both crown Model A, while the cost function crowns Model B. Accuracy is fooled by A's big ; treats FP and FN symmetrically, so B's flood of false alarms tanks its score. But real-world cost weights a miss heavier than a false alarm, flipping the decision to B. The takeaway: when the two error types carry very different real-world costs, neither accuracy nor is the right selection criterion — you must minimise an explicit cost function that encodes those weights. This is exactly Cost-Sensitive Learning and Model Selection Criteria.
Exercise 5.2
You must choose one operating threshold. At threshold : . At : — using the cost rule . Which threshold wins, and sketch how this connects to picking a point on the ROC curve.
Recall Solution
Cost at each threshold:
- : .
- : . → wins (cost 90 < 155). Its higher recall (fewer FN) pays off because each FN costs an FP.
ROC connection. The ROC curve plots TPR (= recall) on the vertical axis against FPR on the horizontal axis (both defined above the exercises). Each threshold is one point:
- : , .
- : , . sits higher and to the right; lower and to the left. Sliding the threshold traces the whole ROC curve, and the cost ratio picks which point on that curve is optimal — the tangent point of an iso-cost line. See ROC Curve and AUC and Binary Classification Thresholds.

Recall Self-test recap (reveal each answer)
Below, read the prompt, answer in your head, then check against the text after the dash.
- Precision's denominator? — predicted positives, .
- Recall's denominator? — actual positives, .
- When is precision undefined? — when (you never predicted positive).
- When is recall undefined? — when (no actual positives in the data).
- FPR formula? — .
- For class , where does its FN live? — the row off-diagonal (real 's sent elsewhere).
- For class , where does its FP live? — the column off-diagonal (others stamped ).
- Why does micro-recall equal accuracy in single-label multi-class? — summed TP = diagonal, and = all samples.
- When is the wrong selection metric? — when FP and FN have very different real-world costs.