Sub topic 13
When AUC misleads
This chapter assumes you can build a ROC curve by sweeping a threshold, you know that AUC is the area under it, and you have used roc_auc_score in scikit-learn. It covers cases where a high AUC does not mean a model is good for your task, and cases where two models with equal AUC behave very differently.
What AUC measures and what it leaves out
AUC is the probability that a randomly chosen positive example gets a higher score than a randomly chosen negative one. It depends only on the ranking of scores across the two classes. That makes it useful for comparing rankers, and it is also the source of every pitfall below.
AUC does not tell you three things:
- Whether the scores are calibrated probabilities.
- How the model performs in the region of the curve your application uses.
- How many of the examples you flag will be real positives at your deployment prevalence.
The sections below go through each gap.
AUC ignores calibration
Any strictly increasing transformation of the scores leaves the ranking unchanged, so it leaves AUC unchanged. A model that outputs 0.9 for everything it likes and a model that outputs 0.5001 can have identical AUC.
import numpy as np
from sklearn.metrics import roc_auc_score, log_loss
y_true = np.array([0, 0, 1, 1])
y_score = np.array([0.1, 0.4, 0.35, 0.8])
squashed = y_score ** 4 # strictly increasing on [0, 1], so the ranking is unchanged
print(roc_auc_score(y_true, y_score)) # 0.75
print(roc_auc_score(y_true, squashed)) # 0.75
print(round(log_loss(y_true, y_score), 3), round(log_loss(y_true, squashed), 3))Both AUC values are 0.75, but the log losses differ because log loss reads the score values. If a downstream system treats the score as "a 30% chance of fraud", check calibration separately with a reliability diagram or log loss. A high AUC says nothing about it.
Equal AUC, different curves
AUC collapses a curve into one number. Two curves can enclose the same area and cross each other. Consider two models with these ROC points, joined by straight lines:
- Model A: (0, 0), (0.1, 0.6), (1, 1)
- Model B: (0, 0), (0.4, 0.9), (1, 1)
import numpy as np
from sklearn.metrics import auc
fpr_a, tpr_a = np.array([0, 0.1, 1.0]), np.array([0, 0.6, 1.0])
fpr_b, tpr_b = np.array([0, 0.4, 1.0]), np.array([0, 0.9, 1.0])
print(round(auc(fpr_a, tpr_a), 3), round(auc(fpr_b, tpr_b), 3)) # 0.75 0.75
for f in (0.1, 0.4):
print(
f,
round(float(np.interp(f, fpr_a, tpr_a)), 3),
round(float(np.interp(f, fpr_b, tpr_b)), 3),
)
# 0.1 0.6 0.225
# 0.4 0.733 0.9Both areas are 0.75. At a false positive rate of 0.1, Model A finds 60% of positives and Model B finds 22.5%. At 0.4, Model B leads with 90% against 73.3%.
If your application can only afford a few false alarms, such as a human review queue with limited capacity, Model A is the better choice despite the tie. If it must catch nearly every positive and can tolerate many false alarms, Model B is better.
When curves cross, compare them on the region that matters. Two common options are:
- Read off TPR at a fixed FPR, as the code above does with
np.interp. - Compute a partial AUC.
roc_auc_score(y_true, y_score, max_fpr=0.1)returns the area up to FPR 0.1, rescaled by the McClish correction so that 0.5 means chance level and 1.0 means perfect.
The bounds on the partial AUC matter. The raw area up to max_fpr is at most max_fpr. After standardization the result goes from 0.5 for a chance-level classifier to 1.0 for a perfect one. Do not compare a standardized partial AUC to a full AUC.
Prevalence hides false alarm cost
TPR and FPR are each computed within one class. TPR divides by the number of positives, and FPR divides by the number of negatives. So the ROC curve does not change when you change the ratio of positives to negatives, as long as the score distributions within each class stay the same.
That is a strength when you compare models across datasets with different class mixes. It is a weakness when you want to know how many flagged examples are real. Precision divides by everything flagged, so it depends on prevalence.
def precision(prevalence, tpr, fpr, n=10_000):
pos = n * prevalence
neg = n - pos
tp = tpr * pos
fp = fpr * neg
return tp / (tp + fp)
for prev in (0.5, 0.01, 0.001):
print(prev, round(precision(prev, tpr=0.9, fpr=0.1), 3))
# 0.5 0.9
# 0.01 0.083
# 0.001 0.009The operating point (TPR 0.9, FPR 0.1) is the same in all three runs, which is a point on a ROC curve with an AUC near 0.9. At 1% prevalence only about 8% of alerts are real. At 0.1% prevalence it is under 1%.
This is why the previous chapter's precision-recall curves matter on imbalanced data. A model with a good ROC curve can still be useless at low prevalence, because a small FPR multiplied by a huge number of negatives gives a large number of false alarms.
Other ways AUC misleads
| Pitfall | What goes wrong | What to check |
|---|---|---|
| Crossing curves | Equal AUC hides different behavior at low and high FPR | Partial AUC or TPR at the affordable FPR |
| Low prevalence | A tiny FPR still produces many false alarms | Precision and PR curve at deployment prevalence |
| Miscalibrated scores | AUC is blind to monotone distortions | Reliability diagram, log loss, Brier score |
| Ties in scores | Coarse scores create few curve points and straight segments | Number of distinct scores, tie handling |
| AUC below 0.5 | Scores are inverted, or labels are flipped | Label encoding, sign of the score |
| Small test sets | AUC estimate is noisy | Bootstrap interval |
| Distribution shift | Score distributions per class change after deployment | Monitor AUC on recent labeled data |
| Leakage | Features encode the label, giving an implausibly high AUC | Feature audit, time-based split |
Three of these deserve more detail.
Ties
When many examples share a score, the curve jumps diagonally across the tie group instead of tracing a staircase. A tied positive-negative pair counts as one half in the ranking interpretation. A model that outputs only a few distinct values, such as a shallow decision tree, has a coarse curve with few vertices. Its AUC is correct, but it says little about thresholds you could choose, because only a few thresholds exist.
AUC below 0.5
An AUC of 0.2 is not a bad model. It is a good model with the score direction reversed, because 1 - score would give an AUC of 0.8. This usually comes from passing the probability of the wrong class, or from a mismatch between pos_label and the label encoding. Fix the plumbing before you celebrate or discard the model.
Pooling across groups
If you pool several groups into one test set, the pooled AUC can differ from every per-group AUC. Suppose group 1 has a low base rate and lower scores overall, and group 2 has a high base rate and higher scores. Ranking positives from group 2 above negatives from group 1 is easy, and that inflates the pooled AUC. Compute AUC within each group that matters to you, not only on the pooled data.
Leakage and implausible AUC
An AUC close to 1.0 on a hard problem usually points to a bug. Typical causes:
- A feature derived from the label, such as a field recorded after the outcome.
- Duplicate or near-duplicate rows on both sides of the train-test split.
- Preprocessing fit on the full dataset before splitting.
Treat a surprising result as a prompt to audit the pipeline. Splitting by time or by entity, such as by patient or by customer, often removes the inflation.
A reporting checklist
Before you trust a reported AUC, ask:
- How many positives and negatives are in the test set?
- What is the deployment prevalence, and what is the precision at the intended threshold?
- Do the compared curves cross, and in which FPR range do you operate?
- Are the scores used as probabilities, and if so, are they calibrated?
- Is there an interval on the AUC, such as the bootstrap interval covered in the next chapter?
Exercise
A fraud model has TPR 0.8 and FPR 0.02 at its chosen threshold, and its ROC AUC is 0.95. Fraud occurs in 0.2% of transactions. Out of 100,000 transactions, about how many alerts will be real fraud, and what is the precision? Does the high AUC change your concern?
Show answer
Positives: 0.002 × 100,000 = 200. Negatives: 99,800. True positives: 0.8 × 200 = 160. False positives: 0.02 × 99,800 = 1,996. Alerts: 160 + 1,996 = 2,156. Precision: 160 / 2,156 ≈ 0.074, so about 7% of alerts are real fraud. The high AUC does not change the concern. AUC is unaffected by prevalence, but precision is not, so the review team will see about 12 false alarms for every real case. Report precision at this prevalence and consider whether the review capacity can absorb the alerts.
Exercise
Two models both have AUC 0.82. Model X has TPR 0.55 at FPR 0.05, and Model Y has TPR 0.30 at FPR 0.05. Your team can review only 5% of legitimate cases as false alarms. Which model do you pick, and what would make you reconsider?
Show answer
Pick Model X, because it finds 55% of positives at the affordable FPR of 0.05 against 30% for Model Y. The equal AUC is misleading here because the curves must cross somewhere, so Model Y must be better at a higher FPR. Reconsider if the affordable FPR rises, if the measurements come from a small test set (check a bootstrap interval on TPR at FPR 0.05), or if the deployment prevalence differs enough that precision at that point becomes unacceptable.