Walk me through classification evaluation metrics — precision, recall, F1, AUC
Written by the mlprep team · Updated
Walk me through precision, recall, F1, AUC-ROC, and AUC-PR. When would you use each, and what does each actually measure?
Confusion matrix foundation#
Predicted + Predicted -
Actual + TP FN
Actual - FP TN
- Precision = TP / (TP + FP): of all predicted positives, what fraction was actually positive. Penalizes false alarms.
- Recall (sensitivity) = TP / (TP + FN): of all actual positives, what fraction was predicted positive. Penalizes missed positives.
- Specificity = TN / (TN + FP): of all actual negatives, what fraction was correctly rejected.
F1 score#
Harmonic mean of precision and recall:
F1 = 2·P·R / (P + R)
Harmonic mean punishes large imbalances between P and R — a model with P=0.99, R=0.01 gets F1=0.02, not 0.5. Forces both to be high.
F-β: generalizes F1 to weight recall β× more than precision:
F_β = (1 + β²) · P·R / (β²·P + R)
Use β > 1 when missing positives is more costly (fraud: β=2). β < 1 when false alarms are more costly.
AUC-ROC#
ROC curve: plot TPR (recall) on y-axis vs FPR (= FP rate = FP/(FP+TN)) on x-axis as you sweep the decision threshold from 1 to 0.
- Perfect model: point (0, 1) — AUC = 1.0
- Random model: diagonal line — AUC = 0.5
AUC-ROC interpretation: the probability that a randomly chosen positive example is scored higher than a randomly chosen negative example.
Why AUC-ROC misleads under imbalance#
With 0.1% positives, FPR = FP / (FP + TN). The denominator is huge (many true negatives). Even a model that generates many false alarms has a small FPR numerically. AUC-ROC looks good while the model produces terrible precision.
AUC-PR (precision-recall curve)#
Plot precision (y) vs recall (x) as threshold sweeps. AUC-PR is the area under this curve.
- Perfect model: area = 1.0
- Random model: area ≈ prevalence (fraction of positives)
For a dataset with 0.1% positives, a random model has AUC-PR ≈ 0.001 — dramatically lower than the 0.5 baseline of AUC-ROC. This makes small improvements in AUC-PR meaningful and visible.
Use AUC-PR for imbalanced problems. Use AUC-ROC when classes are roughly balanced.#
When to use what#
| Metric | Use when | |--------|----------| | Accuracy | Classes balanced, errors symmetric in cost | | Precision | False positives expensive (spam filter: don't block legitimate mail) | | Recall | False negatives expensive (cancer screening: don't miss cases) | | F1 | Single number, both FP and FN matter equally | | AUC-ROC | Balanced classes, comparing models at all thresholds | | AUC-PR | Imbalanced classes (fraud, rare disease) |
Setting the threshold#
Model outputs a score; the threshold converts to a binary decision. Default is 0.5 but this is almost never optimal. Pick the threshold that maximizes your actual business metric on the validation set. Plot the PR curve, pick the point that satisfies your precision or recall requirement.
Metric choice by product domain#
This is where senior answers separate from junior ones — tying metrics to product constraints, not just data properties.
Fraud detection: optimize for high recall. A missed fraud (false negative) costs $500 in chargeback and customer trust. A false alarm costs a fraud analyst 2 minutes of review time. Accept low precision, tune threshold for recall ≥ 95%, use F-β with β=2 or β=3. Evaluate with AUC-PR since fraud rates are 0.1-1%.
Medical diagnosis (cancer screening): missing a positive (false negative) may mean delayed treatment — high clinical cost. False positives cause unnecessary follow-up tests — lower but non-zero cost. Generally optimize recall with a threshold that bounds false positive rate, but the exact tradeoff depends on the disease and downstream test cost. Never optimize accuracy.
Ads CTR prediction: the model output is a probability used in auction pricing (bid = value × predicted_CTR). You need calibration — the probability must be accurate in absolute terms, not just rank-ordered. A miscalibrated model distorts auction prices systematically. AUC measures rank quality but not calibration. Track both.
Search ranking: binary classification metrics are wrong here — ranking is the task. Use NDCG@k (graded relevance, position-discounted), MRR (mean reciprocal rank, for single-answer queries), or Precision@k. AUC is irrelevant for ranking.
Content moderation: false negatives (harmful content stays up) cause user harm and regulatory risk. False positives (legitimate content removed) cause creator churn and free speech concerns. The right tradeoff is a policy decision, not an ML decision — ML gives the score, policy sets the threshold. Often: high precision at high-confidence thresholds, human review for the uncertain middle band.
Recommendation systems: single-item precision/recall is usually wrong. Users care about the quality of their overall feed, not whether one specific item was surfaced. Use coverage (what fraction of the catalog is recommended), diversity, and engagement-based metrics (session length, return rate) alongside ranking metrics.
Senior/staff considerations#
The senior move is to choose metrics from the decision being made, not from the model type. Start with the cost matrix: what is the cost of a false positive, false negative, delayed decision, human review, and user trust damage? Then choose the metric and thresholding strategy.
For production, distinguish:
- Model discrimination: AUC-ROC, AUC-PR, rank correlation. Can the model order examples well?
- Decision quality: precision, recall, cost-weighted utility at the chosen threshold. Does the operating point make sense?
- Probability quality: calibration, Brier score, reliability by segment. Are scores meaningful probabilities?
- System quality: latency, coverage, fairness slices, review capacity, long-term retention, guardrails.
A staff-level answer should also mention that thresholds are product policy. ML supplies calibrated risk scores and tradeoff curves; product/legal/ops choose the operating point. For example, a moderation system may use high-confidence auto-remove, high-confidence allow, and human review for the uncertain middle, instead of one global threshold.
Common traps#
- Reporting accuracy on imbalanced data.
- Optimizing F1 when false positives and false negatives have very different costs.
- Choosing AUC when the product only operates at one high-precision or high-recall threshold.
- Ignoring calibration when scores feed bids, risk decisions, or expected value.
- Reporting only aggregate metrics instead of segment and cohort metrics.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Precision = how much FP cost you. Recall = how much FN cost you. F1 = harmonic mean, punishes imbalance between them. AUC-ROC measures rank quality; random = 0.5, but misleadingly high under class imbalance. AUC-PR better for imbalanced problems — random = prevalence. Always pick threshold based on business cost, not 0.5.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- Your medical screening model has 95% recall but only 10% precision. Is this acceptable? How do you explain the trade-off to a non-technical stakeholder?
- How do you compare two models when one has higher AUC-ROC but the other has higher AUC-PR?
- What is the Matthews Correlation Coefficient (MCC) and when is it preferred over F1?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions