Sub topic 13
When AUC misleads
This chapter assumes you can build a ROC curve, read TPR and FPR, and interpret AUC as the probability that a random positive outscores a random negative. It covers cases where a high AUC still hides a problem.
AUC ignores the scale of the scores
AUC depends only on the ordering of scores. Any strictly increasing transformation leaves it unchanged, so it says nothing about calibration. A model that outputs 0.51 for every positive and 0.49 for every negative has the same AUC as one that outputs 0.99 and 0.01.
import numpy as np
from sklearn.metrics import roc_auc_score
y_true = np.array([0, 0, 1, 1])
y_score = np.array([0.1, 0.4, 0.35, 0.8])
print(roc_auc_score(y_true, y_score)) # 0.75
print(roc_auc_score(y_true, y_score ** 3)) # 0.75
print(roc_auc_score(y_true, 1 - y_score)) # 0.25Cubing the scores keeps the same ranking, so AUC stays at 0.75. Flipping the scores gives 0.25. An AUC well below 0.5 usually means the score direction is reversed, or the positive label is wrong. It does not mean the model has no signal.
If you need to use the scores as probabilities, check calibration separately, for example with a reliability diagram or the Brier score.
Heavy class imbalance
FPR divides by the number of negatives. When negatives vastly outnumber positives, a small FPR can still mean many false alarms.
Suppose a test set has 100 positives and 100,000 negatives. At one threshold, TPR is 0.8 and FPR is 0.05.
| Quantity | Calculation | Value |
|---|---|---|
| True positives | 0.8 × 100 | 80 |
| False positives | 0.05 × 100,000 | 5,000 |
| Precision | 80 / (80 + 5,000) | about 0.016 |
The ROC point looks strong, but 98% of the flagged cases are wrong. Precision-recall curves expose this because precision uses false positives relative to predicted positives, not relative to all negatives. When you care about the rare class, report average precision or plot the precision-recall curve next to the ROC curve.
Crossing curves and the wrong region
AUC compresses the whole curve into one number, and it counts thresholds you will never use. Two models can share an AUC while behaving very differently where you operate.
- Model A may be better at low FPR and worse at high FPR.
- Model B may do the opposite.
- If the application tolerates only a 1% false positive rate, the region above 10% FPR is irrelevant.
Plot the curves before you trust the numbers. For a restricted range, roc_auc_score(y_true, y_score, max_fpr=0.1) computes a standardized partial AUC up to that FPR.
Other common pitfalls
- Unequal costs. AUC weights false positives and false negatives symmetrically across thresholds. A real deployment has specific costs, so choose a threshold with those costs in mind.
- Distribution shift. Prevalence or feature changes after deployment can move the curve. A held-out AUC describes the test distribution only.
- Small samples. With few positives, AUC is noisy. Estimate its uncertainty, for example with a bootstrap, before declaring one model better.
- Leakage and grouping. Duplicate or related examples across train and test sets inflate AUC. Split by group when examples are not independent.
Exercise
A test set has 100 positives and 100,000 negatives. At a threshold, TPR is 0.9 and FPR is 0.01. What is the precision, and what does it suggest about relying on the ROC curve alone?
Show answer
True positives are 0.9 × 100 = 90. False positives are 0.01 × 100,000 = 1,000. Precision is 90 / (90 + 1,000), about 0.083. The ROC point looks excellent, but over 90% of the predicted positives are false. A precision-recall curve would show this problem directly.