Definition
Fit a logistic regression of the observed outcome on the logit of the predicted probability p:
logit( P(y = 1) ) = a + b × logit( p )
A perfectly calibrated model gives a = 0 and b = 1. A slope below 1 means the model is overconfident: its high probabilities are too high and its low ones too low, the usual sign of overfitting. An intercept away from 0, at a slope of 1, means the average level is wrong, for instance after a change in the default rate. Platt scaling uses the same regression as a correction: the fitted a and b, estimated on data held out, are applied to new predictions.
Worked example
A model produces probabilities that are too extreme. We measure its calibration on a calibration sample, apply Platt scaling, and check the result on a separate test sample.
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score
rng = np.random.default_rng(24)
def sample(n):
z = rng.normal(-2.2, 1.0, n) # true log odds
y = (rng.random(n) < 1 / (1 + np.exp(-z))).astype(int)
p = 1 / (1 + np.exp(-(1.6 * z + 1.1))) # the model: right ranking, too extreme
return p, y
logit = lambda p: np.log(p / (1 - p)).reshape(-1, 1)
def slope_intercept(p, y):
m = LogisticRegression(C=1e6).fit(logit(p), y)
return m.intercept_[0], m.coef_[0, 0], m
p_cal, y_cal = sample(5000); p_test, y_test = sample(20000)
a, b, platt = slope_intercept(p_cal, y_cal)
p_fixed = platt.predict_proba(logit(p_test))[:, 1]
for name, p in [("raw model", p_test), ("after Platt scaling", p_fixed)]:
a2, b2, _ = slope_intercept(p, y_test)
top = p >= np.quantile(p, 0.9)
print(f"{name:20s} slope = {b2:.2f} intercept = {a2:+.2f} AUC = {roc_auc_score(y_test, p):.3f} "
f"riskiest tenth: predicted {p[top].mean():.3f}, observed {y_test[top].mean():.3f}")Output, produced by running the code above when this page was built:
raw model slope = 0.63 intercept = -0.68 AUC = 0.750 riskiest tenth: predicted 0.584, observed 0.401 after Platt scaling slope = 1.02 intercept = +0.04 AUC = 0.750 riskiest tenth: predicted 0.390, observed 0.401
The raw model predicts far more defaults in its riskiest tenth than actually occur. After the correction the slope is close to 1 and predicted and observed rates agree. The AUC is identical before and after: calibration and ranking are separate properties.
Where it misleads
- Slope and intercept are averages over the score range. A model can have a slope of 1 and be miscalibrated in one segment or one band, so calibration is also read by band and by segment.
- The correction must be fitted on data the model was not trained on. Fitted on the training data, it hides the overfitting it was meant to reveal.
- Platt scaling assumes the distortion is a straight line on the logit scale. Isotonic regression drops that assumption and needs more data: on small samples it overfits, as Niculescu-Mizil and Caruana measured.
- Calibration drifts with the default rate. A model calibrated in a good year over-predicts or under-predicts in the next, with an unchanged Gini.
Calibration is scored with the Brier score or the log loss, which reward both calibration and sharpness.
In our work
In our credit model validation report the boosting model had a calibration slope of 1.00 on the sealed holdout, against 1.14 for the scorecard benchmark, and calibration was checked by segment as well.
Service: machine learning and model validation Research note: credit model validation, a worked report
References
- Niculescu-Mizil, A., Caruana, R. (2005). Predicting good probabilities with supervised learning. Proceedings of the 22nd International Conference on Machine Learning, 625-632. doi:10.1145/1102351.1102430
- Van Calster, B., McLernon, D. J., van Smeden, M., Wynants, L., Steyerberg, E. W. (2019). Calibration: the Achilles heel of predictive analytics. BMC Medicine, 17, 230. doi:10.1186/s12916-019-1466-7
- scikit-learn developers (2026). Probability calibration. scikit-learn user guide. scikit-learn.org/stable/modules/calibration.html