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.

Not startedJump to quiz

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).

00.250.50.75100.250.50.751false positive rate (1 − specificity)true positive rate (sensitivity)perfect
Strong model (AUC ≈ 0.96)Weak model (AUC ≈ 0.76)Random guessing (AUC = 0.5)
Each point on a curve is one threshold. Curves closer to the top-left corner are better. The diagonal is a model that ranks at random.
  • 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

ThresholdFlaggedTPFPTPRFPR
0.80.9100.50
0.650.9, 0.7110.51/3
0.50.9, 0.7, 0.62111/3
0.1all five2311

Raising the threshold lowers both TPR and FPR.

What AUC does and doesn't tell you

AUC tells youAUC does not tell you
How well the model ranks positives above negativesWhich 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 balanceWhether 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

ROC: TPR vs FPR over all thresholds. AUC = P(random positive scored above random negative). 0.5 random, 1 perfect.

AUC by counting

For every (positive, negative) pair, score 1 if the positive ranks higher, 0.5 if tied. AUC = total / (#pos × #neg).

AUC misreadings

AUC 0.9 ≠ 90% accuracy. It doesn't choose a threshold or account for costs.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1conceptWhat does an ROC curve plot?
Q2calculatePositives are scored 0.8, 0.5, 0.4; negatives are scored 0.6, 0.3. What is the AUC, by counting pairs?
Q3calculateThere are 4 positives and 6 negatives. At some threshold, 3 positives and 2 negatives are flagged. Where is this point on the ROC curve?
Q4interpretModel A has AUC 0.92 and model B has AUC 0.55. Which statement is best supported?
Q5conceptWhy is AUC called "threshold-independent", and what can't it tell you?