Lesson 4.10 · 10 min read · about 55 min to master at a very slow pace
ROC Curve and AUC
The ROC curve shows every sensitivity–specificity trade-off a model can offer. AUC summarises it as the probability a random positive outranks a random negative. How to compute both by hand.
The curve
For every threshold from 1 down to 0, compute the true positive rate (sensitivity) and the false positive rate (1 − specificity). Plot TPR against FPR. That's the ROC curve (receiver operating characteristic).
- Top-left corner (FPR 0, TPR 1) is perfect.
- The diagonal is random guessing: flagging a random fraction of cases catches the same fraction of positives and negatives.
- Moving along a curve = moving the threshold. The curve itself doesn't change with the threshold.
AUC
Meaning
AUC (area under the ROC curve) is the probability that a randomly chosen positive gets a higher score than a randomly chosen negative. 0.5 = random ranking; 1.0 = perfect ranking.
AUC by counting pairs
Positives scored ; negatives . There are positive–negative pairs. A pair is "correct" if the positive scores higher:
- 0.9 beats all three negatives: 3
- 0.6 beats 0.3 and 0.2 but not 0.7: 2
AUC . (Ties count as half.)
Tracing the curve from the same scores
| Threshold | Flagged | TP | FP | TPR | FPR |
|---|---|---|---|---|---|
| 0.8 | 0.9 | 1 | 0 | 0.5 | 0 |
| 0.65 | 0.9, 0.7 | 1 | 1 | 0.5 | 1/3 |
| 0.5 | 0.9, 0.7, 0.6 | 2 | 1 | 1 | 1/3 |
| 0.1 | all five | 2 | 3 | 1 | 1 |
Raising the threshold lowers both TPR and FPR.
What AUC does and doesn't tell you
| AUC tells you | AUC does not tell you |
|---|---|
| How well the model ranks positives above negatives | Which threshold to use |
| Performance across all thresholds (threshold-independent) | Accuracy, precision or cost at your operating point |
| A fair comparison of rankers, unaffected by class balance | Whether the probabilities are well calibrated |
AUC ≠ accuracy
An AUC of 0.92 doesn't mean 92% accuracy. And a model with AUC 0.55 isn't necessarily useless at every threshold, though it ranks only slightly better than chance.
Cheatsheet
ROC & AUC
AUC by counting
AUC misreadings
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.