2.6.7 · D5Model Evaluation & Selection

Question bank — Accuracy, precision, recall, F1-score

2,017 words9 min readBack to topic

Every metric below is built from four counts — the four ways a yes/no prediction can land against reality. We call the class we care about the positive class (e.g. "has cancer", "is spam"). The confusion matrix, sketched below, is the picture that holds all four.

Reading the figure: it is a 2×2 grid. The columns are what the model predicted ("Predicted +" on the left, "Predicted −" on the right); the rows are what was actually true ("Actually +" on top, "Actually −" below). The mint (green) diagonal holds TP and TN — where prediction agreed with reality. The coral off-diagonal holds FN (top-right) and FP (bottom-left) — where it went wrong. The lavender arrow runs down the "Predicted +" column (TP over TP+FP) — that column is precision. The coral arrow runs across the "Actually +" row (TP over TP+FN) — that row is recall. Keep this picture in mind for every trap.

Recall The four counts, in words
  • TP (true positive) — said positive, was positive. A correct catch.
  • TN (true negative) — said negative, was negative. A correct pass.
  • FP (false positive) — said positive, was negative. A false alarm.
  • FN (false negative) — said negative, was positive. A miss. Precision watches FP (alarms). Recall watches FN (misses). Accuracy counts everything equally.

The next picture shows why precision and recall pull against each other. As you slide the decision threshold, one climbs while the other slips — the whole story lives on one curve.

Reading the figure: two side-by-side panels. Left panel is the Precision-Recall Curve: the horizontal axis is recall , the vertical axis is precision , and the lavender curve traces every threshold setting. The two coral dots mark a high-precision/low-recall point (upper-left) and a high-recall/low-precision point (lower-right) — proof you cannot push both to the top-right corner. Right panel is the ROC Curve and AUC: the horizontal axis is the false positive rate (FPR, defined above), the vertical axis is the true positive rate (TPR = recall), the slate curve is the model, the butter dashed line is a coin-flip baseline, and the mint shaded area between them illustrates the AUC (area under the curve). Both curves refuse to let you have everything at once.


True or false — justify

Accuracy is always a good summary of model quality
False — on imbalanced data a model that always predicts the majority class scores high accuracy while catching zero minority cases; accuracy hides the errors that matter. See Class Imbalance Handling.
A model with 100% precision must be a strong model
False — you can hit 100% precision by predicting positive exactly once, correctly, and staying silent otherwise (TP=1, FP=0, FN=huge). Precision says nothing about the misses.
Precision and recall both have TP in the numerator, so they measure the same thing
False — same numerator TP, but different denominators: precision divides by TP+FP (the total the model predicted positive), while recall divides by TP+FN (the total that was actually positive). Predicted-positive versus actually-positive — they track opposite failures.
F1 is just the average of precision and recall
False — it's the harmonic mean, with = precision and = recall. The harmonic mean collapses toward the smaller value, so F1 punishes a low score in either metric — an arithmetic average would forgive it.
If you improve recall, precision can never go down
False — lowering the decision threshold to catch more positives usually adds false alarms too, so recall rises while precision falls. This trade-off is the whole point of Threshold Optimization.
Recall of 90% means 90% of the model's positive predictions were correct
False — that's precision. Recall of 90% means 90% of the actual positives were found; the model may still be drowning in false alarms.
A confusion matrix is only defined for binary problems
False — it generalizes to any number of classes as a square grid (row = actual, column = predicted); the diagonal holds correct predictions. See Confusion Matrix.
F1 = 0 whenever either precision or recall is 0 (with both well-defined)
True — assuming precision and recall are themselves defined, the numerator contains both as factors, so if either is zero the whole thing is zero. A model that fires but never correctly (TP=0, FP>0, FN>0) has zero recall and zero precision and thus F1=0.
Swapping which class you call "positive" leaves precision and recall unchanged
False — TP, FP, FN are all defined relative to the positive class, so relabeling reshuffles them completely. Always state which class is positive before quoting these numbers.

Spot the error

"My spam filter is 99% accurate on a set that is 99% not-spam, so it's excellent."
The 99% not-spam class alone gives 99% accuracy to a filter that catches nothing. Accuracy is dominated by the majority class here; report precision/recall on the spam class instead.
"Precision = TP / (TP + FN)."
Wrong denominator — that formula is recall. Precision is TP / (TP + FP): divide by everything you predicted positive, not by everything that was positive.
"To balance precision and recall, take (P + R) / 2."
That arithmetic mean lets one metric hide a disaster in the other (0.99 and 0.01 average to 0.50, but their harmonic mean is under 0.02). Use the harmonic mean (F1), which stays near the worse of the two.
"Recall doesn't depend on true negatives, so TN is a useless count."
TN is invisible to precision, recall, and F1 — true — but it matters for accuracy and for the ROC Curve and AUC via the false-positive rate (FPR = FP / (FP + TN)). It's not useless, just outside those three metrics.
"F1 improved from 0.60 to 0.70, so both precision and recall went up."
Not necessarily — F1 can rise while one metric climbs and the other slips, as long as the harmonic mean lands higher. Always inspect precision and recall separately, not just F1.
"A false positive and a false negative are equally bad, so I'll just minimize their total."
In most real problems the costs differ wildly (a missed cancer vs a false alarm). Weighting them equally is exactly what accuracy does — see Cost-Sensitive Learning to encode the true costs.

Why questions

Why does the harmonic mean, not the arithmetic mean, define F1?
Because it is dragged down by the smaller value — it forces both precision and recall to be decent to earn a high score, rejecting lopsided models.
Why is high precision the priority for a spam filter but high recall for cancer screening?
A spam false positive deletes an important email (costly), so we minimize FP → precision. A cancer false negative sends a sick patient home (catastrophic), so we minimize FN → recall.
Why can accuracy and F1 disagree about which model is better?
Accuracy weights TP and TN equally and is inflated by a large easy class; F1 ignores TN entirely and focuses on positive-class performance. On imbalanced data they optimize different things.
Why does moving the classification threshold trade precision against recall?
A lower threshold labels more items positive — catching more true positives (recall up) but also admitting more false positives (precision down). The threshold is the dial between the two; the Precision-Recall Curve plots the whole trade-off.
Why do we report precision and recall per class in multi-class or multi-label settings?
A single number would blend a strong class with a failing one and hide the failure. Per-class metrics expose exactly where the model breaks — essential in Multi-Label Classification.
Why is F1 preferred over accuracy on imbalanced datasets?
F1 excludes TN, so the huge majority-class-correct count cannot inflate it; it forces the model to actually find and be right about the rare positive class.

Edge cases

What is recall when there are zero actual positives in the data?
Undefined — the denominator TP+FN is 0. Recall has no meaning when the positive class never occurs; you cannot "find" cases that don't exist.
What is precision when the model never predicts positive?
Undefined — TP+FP = 0, so 0/0. The model made no positive claims, so "how often were your claims right?" has no answer; conventionally treated as 0 or excluded.
When is F1 itself undefined rather than just 0?
F1 is 0 only when precision and recall are both defined and at least one is 0. But if precision or recall is undefined (its denominator is 0), then F1 inherits that — the P=0 or R=0 shortcut assumes each ratio has a non-zero denominator.
What are precision, recall, and F1 for a model that predicts positive for every sample?
Recall = 1 (it catches every real positive), but precision drops to the base rate of positives, and F1 sits between — high recall, low precision, mediocre F1. It never misses but cries wolf constantly.
If a model gets every single prediction right, what are all four metrics?
FP = FN = 0, so precision = recall = F1 = accuracy = 1. Perfect prediction is the one point where all metrics agree.
Can F1 exceed both precision and recall?
No — the harmonic mean always lies between the two values (equal to them only when P = R). F1 can never beat the larger of the two, and usually sits closer to the smaller.
What happens to F1 when precision = recall?
The harmonic mean equals that common value, so F1 = P = R. Perfect balance is the only case where F1 coincides with both inputs.
What does a confusion matrix look like when validated with Cross-Validation instead of a single split?
You sum (or average) the four counts across folds, giving a more stable estimate; a metric computed from one small test split can swing wildly by luck.

Recall One-line self-test

Cover everything and answer: "Which count does precision ignore, and which does recall ignore?" Precision ignores FN (misses); recall ignores FP (false alarms). Both ignore TN. ::: If you got this instantly, you understand the whole page — every trap above is a disguised version of this one distinction.