ROC, AUC and PR Curves
Threshold-by-threshold truth, summarized without picking a cut line
ROC and PR curves show how a classifier behaves at every decision threshold. AUC summarizes rank quality but hides calibration; PR-AUC is the honest surface for rare-event problems.
What you will learn
- Construct ROC and PR curves from scores
- Interpret AUC and PR-AUC and know what each summarizes
- Choose the right curve family for imbalanced problems
What is this?
Classifier probability outputs become labels only after a threshold: above it 'positive', below it 'negative'. Sweep that threshold from 1 to 0 and you trace a curve. The ROC curve plots TPR against FPR; the PR curve plots precision against recall. Their area under the curve — AUC (ROC-AUC) and average precision (PR-AUC) — gives a single, threshold-independent number summarizing how well the model ranks positives above negatives.
Why do you need it?
- A score of 0.7 for precision means nothing until you say which threshold produced it — curves show every choice at once.
- ROC-AUC is robust to class ratio for ranking; PR-AUC tells the truth when positives are rare.
- Comparing models by AUC avoids the trap of tuning each one to a different threshold then arguing over scalars.
- The 'elbow' of a curve locates the sweet spot before you set a final threshold.
Mental model
A dimmer switch swept across its range
Sweeping the decision threshold
You don't have to pick bright or off — the curve shows you the entire trajectory of trade-offs as you slide the dimmer, and the area captures how good the range is overall.
How it works
- The model outputs a score (probability) per example; sort the test set by score descending.
- For each possible threshold, tally TPR = TP/(TP+FN) and FPR = FP/(FP+TN); plot them against each other (ROC).
- The ROC curve starts at (0,0) and ends at (1,1); a random model is the diagonal, a perfect model hugs the top-left corner.
- Area under the ROC (AUC) equals the probability that a random positive scores higher than a random negative.
- For the PR curve, plot precision vs recall; the baseline is the class prevalence, and PR-AUC (average precision) summarizes it.
The same classifier as ROC and PR curves.
In production
- A ranking system promotes the model with the higher ROC-AUC because it only needs the best order, not a threshold.
- A fraud team uses PR curves because positives are <0.5% — a PR curve shows whether the top-decile precision is usable.
- A monitoring dashboard tracks PR-AUC drift instead of accuracy because it degrades visibly when fraud patterns shift.
Best practices
- Use ROC-AUC when classes are roughly balanced and ranking matters; switch to PR when positives are rare.
- Report the curve, not just the area — two models can share an AUC with very different curve shapes.
- Compute curves on the same fixed test set; scores at different data distributions are not comparable.
- Pick the point on the curve that matches your operating constraint (e.g., recall ≥ 0.9) before finalizing the threshold.
Common mistakes
- Quoting AUC=0.95 on a 99/1 problem where PR-AUC is 0.3 — the two tell a very different story.
- Interpreting AUC as accuracy; 0.5 is random, 0.8 is decent, regardless of the 'out of 100' intuition.
- Comparing PR-AUC across datasets with different prevalence — it shifts with the positive rate.
- Using probabilities that were not calibrated on a curve analysis and reading them as literal frequencies.
Common issues
ROC-AUC is 0.5 on training dataNo separation signal, or scores are inverted (higher score = more negative)
Check prediction direction and feature quality; try inverting the score if labels were flipped.
PR-AUC looks great but live performance diesTest distribution was not representative or the model was tuned to the curve's lucky region
Cross-validate curves and re-estimate on slices; optimize in the operating region, not the whole area.
Debugging tips
- If ROC looks like a staircase hugging the axes, your scores are too coarse (few unique probabilities).
- A PR curve dropping instantly means the top-scoring examples are mostly false positives — inspect them.
- AUC identical but business result worse? Compare the curves point-by-point in the operating region.
- When AUC is 1.0, suspect leakage or duplicates between train and test before celebrating.
Interview checkpoint
Hands-on lab
- Compute TPR/FPR/precision/recall at every threshold by hand
- Reproduce AUC and average precision without sklearn
- Observe how class imbalance reshapes the PR curve but not the ROC shape
Trace ROC and PR Curves From Scratch
30 min · intermediate
Quick quiz
A random classifier's expected ROC-AUC is:
PR-AUC and ROC-AUC degrade identically when the positive class becomes more rare.