Matching Test Errors to Classifier Metrics: FP, FN, Precision, Recall
Statistics & ExperimentsModel answerLast updated
Link false-alarm and missed-detection errors in hypothesis tests to classifier metrics, explain why precision depends on prevalence, and judge which error hurts more in practice.
Statisticians and ML engineers describe the same mistakes in different vocabularies. Show that you can move between the two.
Consider a yes/no decision, either a hypothesis test or a binary classifier, where the null hypothesis stands for "nothing is going on" and a "positive" result means the null is rejected.
- Define a Type I error and a Type II error. Also define significance level, power, and how each relates to the confusion matrix.
- Explain how these errors connect to false positives, false negatives, precision, and recall. State which of the quantities are conditioned on the true state of the world and which on the model's prediction.
- Describe situations where a Type I error is the more expensive mistake, and situations where a Type II error is. Give concrete examples for each.
- For each of these settings, say what a Type I and a Type II error would look like: fraud detection, spam filtering, medical screening, and an A/B test.
Be explicit about which outcome you label "positive" in each setting.
Hints
Hint 1
Start by fixing a convention: the null is the 'nothing there' state, and positive means rejecting it. Then fill in a 2x2 table of truth versus decision.
Hint 2
Ask which denominator each metric uses. Recall and the Type II rate are both computed over actual positives. Precision is computed over predicted positives, so it cannot equal 1 minus the Type I rate.
Hint 3
Use Bayes' rule with a rare base rate (for example 1% prevalence) to show that a small false positive rate can still produce mostly false alerts.
Hint 4
For cost questions, think about reversibility and what a follow-up check costs. Cheap second-stage verification often justifies a high-recall first stage.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
What a strong answer covers
A good answer maps the two vocabularies correctly, notices which metrics condition on truth versus prediction, and ties error choices to real costs.
1) Definitions
Fix the convention first: the null H₀ means "nothing there" (legitimate, healthy, no effect), and "positive" means we reject H₀.
| Truth: H₀ holds | Truth: H₀ false | |
|---|---|---|
| Decide positive | Type I error (false positive) | True positive |
| Decide negative | True negative | Type II error (false negative) |
- Type I error (α): rejecting a true null, i.e. a false alarm. α = P(predict positive | actually negative), which equals the false positive rate FP / (FP + TN). It is also 1 minus specificity.
- Type II error (β): failing to reject a false null, i.e. a missed detection. β = P(predict negative | actually positive), which equals the false negative rate FN / (FN + TP).
- Power = 1 − β: the chance of catching a real effect.
- Significance level: the α you are willing to tolerate, chosen before looking at data (commonly 0.05).
2) Link to precision and recall
Recall = TP / (TP + FN) = 1 − β = power = true positive rate. Both condition on actual positives, so the correspondence is exact.
Precision does not equal 1 − α. Precision = TP / (TP + FP) conditions on the prediction: P(actually positive | flagged). α conditions on the truth. The quantity 1 − precision is the false discovery rate. The two are linked through the prevalence π:
Precision = (1−β)π / [(1−β)π + α(1−π)]
Worked example. Let α = 5%, recall = 80%, prevalence = 1%.
- True positives per unit population: 0.8 × 0.01 = 0.008
- False positives: 0.05 × 0.99 = 0.0495
- Precision = 0.008 / 0.0575 ≈ 14%
So roughly 86% of alerts are false even though the false positive rate sounds small. This is why ROC curves can look flattering on imbalanced data and precision-recall curves reveal the issue.
Trade-off. For a fixed model and sample size, lowering the decision threshold (like raising α) increases recall and lowers β, but raises the FPR and usually lowers precision. Reducing both errors together requires a better model, better features, or more data (in testing, a larger sample).
Cost-based threshold. With calibrated probabilities, predict positive when P(y=1|x) > C_FP / (C_FP + C_FN). Costly misses push the threshold down; costly false alarms push it up.
3) When each error is worse
Type I is worse when acting on a false alarm is harmful, irreversible, or erodes trust:
- Spam filtering: a real job offer or a verification email sent to spam is effectively lost, whereas a stray spam message in the inbox is a minor nuisance. Favor precision.
- Legal verdicts: convicting an innocent person. The presumption of innocence is a deliberately tiny α.
- Experimentation: shipping a feature with no true effect wastes effort and contaminates later decisions, so α is fixed low and corrected for multiple comparisons.
- Pre-surgery confirmatory tests: a false positive can lead to unnecessary invasive treatment.
Type II is worse when a miss is catastrophic and a false alarm is cheap to clear:
- Medical screening: a missed cancer delays treatment, while a false positive triggers a follow-up test. Favor recall, then confirm with a high-precision second test.
- Safety-critical content moderation or intrusion detection: a missed breach or harmful item costs far more than reviewing a false flag.
- Underpowered experiments: high β means real improvements get discarded, which is why experiments are sized for 80–90% power.
Fraud is context-dependent. A missed fraud causes chargeback loss; a wrongly declined customer causes friction and churn. The right threshold depends on transaction value and customer lifetime value. A common design is tiered: auto-block at very high scores, step-up verification (e.g. a one-time code) in the middle, approve at low scores. The middle tier turns costly false positives into cheap friction.
4) Identifying the error in a scenario
Recipe: state what "positive" means, then ask whether we claimed something that is not there (Type I) or missed something that is (Type II).
| Setting (positive = ...) | Mistake | Type |
|---|---|---|
| Spam filter (spam) | Legitimate email goes to spam | I |
| Spam filter (spam) | Spam reaches the inbox | II |
| Fraud (fraudulent) | Genuine purchase declined | I |
| Fraud (fraudulent) | Stolen-card purchase approved | II |
| Screening (disease) | Healthy patient flagged | I |
| Screening (disease) | Disease missed | II |
| A/B test (H₀: no effect) | Ship a feature with no real lift | I |
| A/B test (H₀: no effect) | Discard a feature that truly helps | II |
The labels swap if you redefine positive. If "positive = legitimate email," a good email sent to spam becomes a false negative. Always declare the convention.
Common mistakes
- Equating α with 1 − precision; that is the false discovery rate and depends on prevalence.
- Confusing precision with specificity (specificity = 1 − α).
- Ignoring the base rate in rare-event problems.
- Claiming one error type is always worse instead of reasoning from costs, or proposing a two-stage system (high-recall screen, high-precision confirmation).
- Reading a p-value as the probability that H₀ is true. It is computed assuming H₀ holds.
- Forgetting that α and β trade off at fixed sample size, and that only more data or a better model improves both.