What is model calibration and how do you fix a miscalibrated model?
Written by the mlprep team · Updated
What does it mean for a model to be calibrated? How would you detect miscalibration, and what techniques exist to fix it?
What calibration means#
A model is calibrated if its predicted probabilities match empirical frequencies. When a model says "80% probability," roughly 80% of those predictions should actually be the positive class.
Formally: P(Y=1 | f(x) = p) = p for all p ∈ [0,1].
Why it matters#
For decision-making: if you're setting a fraud threshold at 0.5, you need to know what 0.5 actually means. If the model outputs 0.5 when the real probability is 0.2, your threshold is wrong. Expected value calculations, business decision rules, and downstream systems that combine probabilities all require calibrated probabilities.
For ranking: if you only care about which examples are ranked higher, calibration doesn't matter. AUC measures rank quality without requiring calibration.
Detecting miscalibration#
Reliability diagram (calibration plot): bin predictions into deciles (0-0.1, 0.1-0.2, ...), plot mean predicted probability vs actual positive fraction per bin. A perfectly calibrated model lies on the diagonal y=x.
- Points above diagonal: model is underconfident (predicted 0.4, actual 0.6 → boost predictions)
- Points below diagonal: model is overconfident (predicted 0.8, actual 0.5 → shrink predictions)
Expected Calibration Error (ECE):
ECE = ∑_b (|b|/n) · |accuracy(b) - confidence(b)|
Weighted average absolute deviation from the diagonal across bins.
Which models are typically miscalibrated?#
- Random forests: tend to push probabilities toward 0.5 (averaging many trees' binary votes). Underconfident.
- Gradient boosting: can be well or poorly calibrated depending on depth and learning rate.
- Naive Bayes: often overconfident due to the independence assumption.
- SVMs: no probabilistic output by default — Platt scaling was invented specifically to post-hoc calibrate SVMs.
- Neural networks: tend to be overconfident, especially large modern models.
Logistic regression is typically well-calibrated if the model is correctly specified.
Calibration methods#
Platt scaling: fit a logistic regression on top of the model's raw outputs using a held-out calibration set:
P(Y=1|s) = sigmoid(a·s + b)
where s is the model's score. Simple, fast, assumes sigmoid-shaped miscalibration. Works well for SVMs, small datasets.
Isotonic regression: fit a non-parametric, non-decreasing (isotonic) function mapping scores to probabilities. More flexible than Platt — can capture any shape of miscalibration. Requires more data to avoid overfitting the calibration mapping.
Temperature scaling (for neural networks): scale logits by a temperature T before softmax:
ŷ = softmax(z / T)
T > 1: softer distribution (less confident). T < 1: sharper. Find T that minimizes NLL on validation set. Simple, single parameter, often very effective. Preserves accuracy (argmax unchanged).
Important: always fit calibration on a held-out set, not the training set. Using training data to calibrate = data leakage.
Cross-validation + calibration#
In CV, apply calibration inside each fold: train base model → calibrate on fold holdout → evaluate. Don't calibrate globally using all of training, then evaluate — that mixes train and calibration data.
Senior/staff considerations#
The first question is whether the product needs calibrated probabilities or only rank order. Calibration matters when probabilities feed thresholds, expected value calculations, auctions, risk scores, triage queues, or another model. If the output only determines ordering, AUC/NDCG may matter more than calibration.
Calibration is also segment-specific. A model can be globally calibrated but badly miscalibrated for new users, a geography, a device type, or a rare class. For production systems, inspect reliability diagrams and ECE by segment, especially for segments that drive policy or revenue decisions.
Calibration is not permanent. It drifts when base rates shift, labels are delayed, acquisition channels change, or the model changes user behavior. For a mature system, monitor:
- predicted probability distribution
- observed outcome rate by score bucket
- ECE or Brier score by segment
- threshold-level precision/recall for decision bands
- label delay and censoring effects
Decision framing#
Use Platt or temperature scaling when miscalibration is mostly monotonic and you have limited data. Use isotonic regression when the curve has a non-sigmoid shape and you have enough held-out examples per score region. Recalibrate only after ruling out label pipeline bugs and population shift so severe that the base model itself needs retraining.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Calibration: predicted probability p means "p% of these cases are actually positive." Detect with reliability diagrams (plot predicted vs empirical) and ECE. Fix with: Platt scaling (logistic regression on scores, simple), isotonic regression (flexible, needs data), temperature scaling (best for neural nets, single parameter). Always calibrate on held-out data. Calibration matters when probabilities drive decisions; AUC-only tasks don't need it.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- A random forest achieves 0.93 AUC but terrible calibration. Would you bother calibrating it? Depends on what?
- How does temperature scaling differ from Platt scaling, and why is temperature scaling preferred for large neural networks?
- You calibrated your model on a validation set. Three months later, the model is deployed in production. Do you expect calibration to hold?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
Your CTR model's calibration degrades months after launch — what causes it and how do you fix it?
How do you evaluate a new ranker using logs from an old policy?
How do you put confidence intervals on ML metrics?
How would you design the click-through rate prediction system for an ads platform?