Sub topic 3
Calibration is not accuracy or AUC
This chapter assumes you know how accuracy and ROC AUC are computed, and that you have read the previous chapter's definition of calibration: among predictions of about 0.8, roughly 80% should be positive.
Three different questions
Each metric answers a different question about a classifier.
- Accuracy asks how often the predicted label is right after a threshold is applied.
- AUC asks how often a random positive gets a higher score than a random negative. It measures ranking quality (discrimination).
- Calibration asks whether the numeric value of the probability matches how often the event happens.
AUC looks only at the order of the scores. Accuracy looks only at which side of the threshold each score falls on. Neither reads the actual probability values, so a model can score well on both and still output untrustworthy numbers.
| Metric | Uses | Unchanged by a monotonic rescaling of scores? |
|---|---|---|
| Accuracy at a fixed threshold | Side of the threshold | Only if the threshold's position in the ranking is preserved |
| ROC AUC | Rank order | Yes |
| Brier score, log loss | Probability values | No |
| Reliability diagram, ECE | Probability values | No |
Demonstration: same ranking, worse probabilities
Any strictly increasing function of the scores leaves the ranking intact. The code below sharpens the probabilities by multiplying their log-odds by 3. The value 0.5 still maps to 0.5, so the labels at threshold 0.5 do not change either.
import numpy as np
from scipy.special import expit, logit
from sklearn.datasets import make_classification
from sklearn.metrics import accuracy_score, brier_score_loss, log_loss, roc_auc_score
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
X, y = make_classification(
n_samples=20000, n_features=20, n_informative=5, n_redundant=10, random_state=0
)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=0)
p = GaussianNB().fit(X_train, y_train).predict_proba(X_test)[:, 1]
p = np.clip(p, 1e-12, 1 - 1e-12)
p_sharp = expit(3 * logit(p))
for name, q in (("original", p), ("sharpened", p_sharp)):
print(
f"{name:<10} acc={accuracy_score(y_test, q > 0.5):.4f} "
f"auc={roc_auc_score(y_test, q):.4f} "
f"brier={brier_score_loss(y_test, q):.4f} "
f"logloss={log_loss(y_test, q):.4f}"
)Accuracy and AUC come out the same for both rows. Brier score and log loss differ, and the sharpened model is more overconfident, so its log loss is typically worse. A metric that cannot distinguish the two models cannot tell you which one has usable probabilities.
Why this matters in practice
Ranking is enough when you only need an ordered list, such as the top 100 leads to call. You need calibration when the number itself is used. Examples are expected-cost calculations, risk scores shown to people, and combining probabilities from several models.
The relationship runs in one direction only:
- A well-calibrated model can have poor AUC. Predicting the base rate for every example is perfectly calibrated and has an AUC of 0.5.
- A model with high AUC can be badly calibrated, as the demonstration shows.
- Post-hoc calibration (Platt scaling, isotonic regression) can improve probability quality without changing AUC much. Platt scaling is strictly monotonic, so its AUC is unchanged. Isotonic regression is only non-decreasing, so it can merge nearby scores into ties and slightly lower AUC.
Common errors
- Reporting a high AUC as evidence that the probabilities are trustworthy.
- Picking the model with the best accuracy when downstream code multiplies its probabilities by costs.
- Judging calibration with accuracy or AUC on the same data that you used to fit the calibrator.
- Assuming a model with low Brier score must rank well. Brier score mixes calibration and discrimination, so check both separately.
Exercise
A model has AUC 0.92, and its predictions of 0.9 are positive only 60% of the time. You apply a strictly increasing transform that maps 0.9 to 0.6 (and every other score to a lower or equal-spaced value in order). What happens to AUC, and does the model become better calibrated?
Show answer
AUC stays at 0.92 because a strictly increasing transform preserves the ranking. The transform can improve calibration, since scores near 0.9 now map to about the 0.6 that is actually observed. This is the idea behind Platt scaling and isotonic regression, though they fit the mapping from held-out data.