ROC-AUC & Precision-Recall Curves
Rank classifiers with ROC-AUC and prefer PR curves under heavy class imbalance.
In plain words
ROC and PR curves show how a model's hits and false alarms change as you make it more or less trigger-happy, and the area under them is a score for how well it ranks positives above negatives.
Think of it like…
Tuning the sensitivity of a smoke detector: the ROC curve shows how many real fires you detect versus false alarms from burnt toast as sensitivity rises, while the PR curve tells you, of all the alarms that sound, how many were real fires, a number that depends on how rare fires are.
Where you’ve seen it
Six scored cases: positives 0.9, 0.8, 0.4 and negatives 0.7, 0.3, 0.2. Of the 3 × 3 = 9 positive-negative pairs, the positive outranks the negative in 8 (0.9 and 0.8 beat all three negatives; 0.4 beats 0.3 and 0.2 but not 0.7), so ROC-AUC = 8/9 = 0.889. Sweeping thresholds gives ROC points (FPR, TPR) = (0, 1/3), (0, 2/3), (1/3, 2/3), (1/3, 1), (2/3, 1), (1, 1) and the area is 2/9 + 6/9 = 8/9. Now a fraud problem with 1% prevalence (1,000 frauds in 100,000). Two models both have ROC-AUC 0.95 and 80% recall at some threshold, but model A has FPR 5% there and model B 0.5%. Model A flags 800 + 0.05 × 99,000 = 5,750 cases with precision 800/5,750 = 13.9%; model B flags 800 + 495 = 1,295 with precision 61.8%. The ROC curves look nearly identical while the PR curves are very different, and the analysts' review capacity makes B the only usable model. The random baseline for AP is 0.01.
Words you’ll hear
- ROC curve / AUC
- TPR versus FPR across thresholds; AUC is the probability a positive outranks a negative.
- PR curve / AP
- Precision versus recall across thresholds; AP summarises it.
- Prevalence baseline
- A random classifier's precision equals the positive rate.
- Operating point
- The threshold chosen on a curve for deployment.
Visual diagram
Theory & deep dive
ROC curves and AUC
For each threshold t, a score ≥ t is positive. TPR = TP/(TP + FN) is recall and FPR = FP/(FP + TN). The ROC curve plots TPR against FPR; the diagonal is random ranking, the top-left corner perfect. ROC-AUC has a clean interpretation: the probability that a random positive receives a higher score than a random negative (ties count half). With positives {0.9, 0.8, 0.4} and negatives {0.7, 0.3, 0.2}, 8 of 9 pairs are ordered correctly, so AUC = 0.889; equivalently the area under the stepwise ROC curve is 2/9 + 6/9 = 8/9. AUC is threshold-free and invariant to class balance (it depends on the score distributions within each class, not on prevalence), and it is insensitive to monotonic transformations of the scores, which means it says nothing about calibration.
Limitations: AUC averages over thresholds you'd never use (high FPR regions), so two models with equal AUC can differ greatly in the low-FPR region that matters for rare events; partial AUC or TPR at a fixed low FPR focus on the relevant region. Also, because FPR divides by the (huge) number of negatives, a tiny FPR can still mean thousands of false positives at low prevalence, which is why ROC curves look flattering for rare-event problems.
Positives 0.9, 0.8, 0.4; negatives 0.7, 0.3, 0.2. Pair outcomes: 0.9 beats 3/3; 0.8 beats 3/3; 0.4 beats 2/3 (loses to 0.7). Total 8/9 = 0.889.
Precision-recall curves, imbalance and choosing a view
The PR curve plots precision against recall across thresholds, and average precision (AP) summarises it (a weighted mean of precisions at each recall step). Unlike ROC, precision depends on prevalence because it includes FP relative to TP: at 1% prevalence and 80% recall, an FPR of 5% gives precision 800/(800 + 4,950) = 13.9%, whereas 0.5% gives 61.8%, even though both models can have ROC-AUC 0.95. The baseline for a random classifier is a horizontal line at the prevalence (AP ≈ 0.01), so always compare AP with it. PR curves focus on the positive class and on the region analysts experience: how many alerts are real at a given recall.
Guidance: use ROC-AUC to compare ranking quality across models and when classes are balanced or both classes matter; use PR curves and AP when positives are rare or false positives are costly (fraud, defects, disease screening), and read precision at a fixed recall or recall at a fixed precision. PR curves aren't monotone and interpolation can mislead, so use scikit-learn's precision_recall_curve and step-wise AP. Neither curve chooses the threshold: select an operating point by cost, capacity (review 500 alerts a day) or constraint (precision ≥ 0.9), and verify on held-out data. Report confidence intervals via bootstrap, and recalibrate probabilities separately if you need them to be actual risks. Finally, evaluate on data with production prevalence, since resampled test sets distort PR curves.
Recall 80% → TP = 800. Model A: FPR 5% × 99,000 = 4,950 FP → precision 13.9%. Model B: FPR 0.5% × 99,000 = 495 FP → precision 61.8%. With capacity for 1,300 reviews a day, only B yields about 800 true frauds in the queue.
How it works, step by step
Step 1 of 41. Get scores on held-out data
Compute predicted probabilities or scores on validation data with production prevalence.
- Don't
- resample the evaluation set
When to use it & trade-offs
What it is
ROC and precision-recall (PR) curves evaluate a classifier across all thresholds rather than at one. The ROC curve plots true-positive rate (recall) against false-positive rate as the threshold sweeps; its area, ROC-AUC, equals the probability that a randomly chosen positive is scored higher than a randomly chosen negative, so it measures ranking quality and is insensitive to class balance. The PR curve plots precision against recall; its area (average precision, AP) depends strongly on prevalence, with a random classifier scoring AP ≈ prevalence. Under heavy imbalance, PR curves expose operational reality (many false alarms) that ROC curves can hide.
Why it matters: A single threshold hides how a model behaves at other operating points, and the best threshold changes with costs and capacity. ROC-AUC lets you compare ranking quality independent of threshold, but at 1% prevalence an AUC of 0.95 can still mean terrible precision. Choosing between ROC and PR views, and reading both correctly, prevents shipping models that look excellent on paper but flood analysts with false positives.
When to reach for it
- Comparing models independent of threshold
- Rare-event detection (fraud, defects, disease)
- Choosing operating points under capacity limits
When to avoid or be careful
- Relying on ROC-AUC alone at 1% prevalence
- Evaluating on resampled data and quoting precision
- Assuming AUC says anything about calibration
Curve-based metrics
Strengths: Threshold-free; prevalence-invariant.
Watch out: Can look excellent for poor rare-event models.
Strengths: Reflects operational precision.
Watch out: Depends on prevalence; harder to compare across datasets.
Strengths: Directly actionable.
Watch out: Single operating point.
Interview signals & numbers to know
When this topic comes up
- “AUC 0.95 but too many false alarms”
- Average precision
- ROC vs PR curves
- Precision at recall 80%
- Pairwise ranking probability
Benchmarks & rules of thumb
- 8/9 = 0.889
- AUC for the six-case example
- 13.9% vs 61.8%
- precision of two AUC-0.95 models at 80% recall
- prevalence
- random baseline for AP (0.01 here)
Common mistakes & follow-ups
Common interview mistakes
- Comparing PR curves from datasets with different prevalence.
- Treating ROC-AUC as accuracy.
- Optimising AUC when only the top of the ranking matters.
Likely interviewer follow-ups
- What does ROC-AUC mean in probability terms?
- Why prefer PR curves under heavy class imbalance?
- How do you choose a threshold from a curve?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply ROC-AUC & Precision-Recall Curves with data science interview Q&A and hands-on practice.