Calibrating Neural Network Probabilities
A neural network's output layer produces numbers that look like probabilities, but a network trained only to get the label right has no incentive to get the confidence right too. Calibration is the separate step that fixes this.
Prerequisites: Logistic Regression, Backpropagation
A network trained to predict "will this trade be profitable" outputs 0.92. Should you size the position as if there is a 92% chance of success? Only if the network is calibrated — if, among every situation where it says 0.92, roughly 92 out of 100 really do turn out profitable. Nothing in ordinary training guarantees that. The network is only ever pushed to put the highest score on the correct label; it is never told anything about what the number itself should mean. Two networks can classify identically and still disagree wildly on confidence, and the one that shouts 0.99 for everything will wreck a strategy that sizes bets on probability even though its hit rate is fine.
The analogy: a weather forecaster who never checks the record
Imagine a forecaster who says "80% chance of rain" every single day it rains and every single day it doesn't, purely because 80% "feels confident." He gets the yes/no call right 80% of the time by luck alone, but his 80% is meaningless — it never lines up with an actual 80% rain frequency. A well-calibrated forecaster is one you could audit: pull every day he said 80%, count how many actually got rain, and find it close to 80. Calibration is exactly that audit applied to a network's softmax output. Getting the rain/no-rain call right (accuracy) and getting the percentage right (calibration) are different skills, and a model can have one without the other.
The maths
Formally, a classifier is perfectly calibrated if, for every confidence level ,
In words: among all the inputs where the model's predicted probability equals , the true fraction that are actually positive is itself. is the true label (1 or 0), is the input, is the model's output score for that input. If never matches the real frequency, the model is miscalibrated.
The standard summary statistic is Expected Calibration Error (ECE). Split predictions into confidence bins (say, 0–10%, 10–20%, ..., 90–100%). In bin , compare the average predicted confidence to the actual accuracy :
In words: for each bin, take the gap between what the model claimed and what actually happened, weight that gap by how many predictions ( out of total) fell in the bin, and add the weighted gaps up. A perfectly calibrated model scores 0.
Modern deep networks systematically over-predict confidence — a phenomenon tied to how they're trained with cross-entropy loss, which keeps rewarding the model for pushing correct-class scores toward 1 long after accuracy has plateaued. The standard fix, temperature scaling, divides the pre-softmax logits by a single learned scalar before the softmax:
In words: stretch every logit down by the same factor before turning them into probabilities. This softens overconfident predictions without changing which class has the highest score — so accuracy is untouched, only the confidence numbers shrink toward something more honest. is fit on a held-out validation set by minimizing the negative log-likelihood there, never on the training set.
Drag the steepness parameter and watch the curve near the edges: a steeper logistic-style curve pushes outputs toward 0 and 1 faster, which is exactly the overconfidence temperature scaling is undoing — pulling that curve back toward a gentler slope so mid-range inputs don't get slammed to the extremes.
Worked example 1: computing ECE by hand
A model made 10 predictions on a test set. Bin them by confidence:
| Bin | Predictions | Avg. confidence | Correct | Accuracy |
|---|---|---|---|---|
| 0.9–1.0 | 4 | 0.95 | 3 of 4 | 0.75 |
| 0.7–0.8 | 4 | 0.75 | 3 of 4 | 0.75 |
| 0.5–0.6 | 2 | 0.55 | 1 of 2 | 0.50 |
Compute each bin's contribution, weight times :
- Bin 1:
- Bin 2:
- Bin 3:
An ECE of 0.09 means: on average, weighted by how often each confidence level occurs, the model's stated probability is off by 9 percentage points. Bin 1 is the problem child — the model says "95% sure" but is only right 75% of the time. That is the classic overconfidence pattern, and it is concentrated exactly where a trader would be tempted to size up the most.
Worked example 2: fixing it with temperature scaling
Take one input where the network's two pre-softmax logits are for classes {profitable, not profitable}. At (no scaling, the raw output):
The model claims 88.1% confidence. Suppose calibration on a validation set finds this network is systematically overconfident and fits . Recompute with logits divided by 2, so :
The predicted class hasn't changed — "profitable" still wins — but the stated confidence dropped from 88.1% to 73.1%. If validation data shows that among all "88% confident" predictions only about 73% were actually correct, this is exactly the right correction, and any downstream code that sizes positions off the probability now sizes them more sanely.
Slide the model complexity control and watch how a model that fits training data ever more tightly (low bias, high variance) tends to also push its own confidence toward the extremes on the training set — the same mechanism that produces the overconfidence temperature scaling corrects, just viewed through error rather than probability.
Accuracy asks "did you get the label right." Calibration asks "was your stated confidence honest." A network optimized purely by cross-entropy on training data nails the first and, especially once it is deep and over-parameterized, routinely fails the second — usually by being overconfident, not underconfident.
What this means in practice
Any system that uses a network's output as an actual probability — position sizing proportional to signal confidence, a risk model that flags "P(default) > 5%", an options-flow classifier feeding a Kelly-style sizing rule — is silently assuming calibration that was never verified. The fix is cheap: hold out a calibration set the model never trained on, fit a single temperature scalar (or a more flexible isotonic regression if one scalar isn't enough), and check ECE before and after. This costs almost nothing computationally and is routinely skipped, which is exactly why it's worth checking.
The trap: calibrating on the training set. Since the network already memorized the training data to some degree, its confidence there looks fine even when it is badly miscalibrated on new data — the overconfidence problem is specifically a generalization-gap phenomenon. Temperature (or any calibration map) must be fit on a held-out split the network never saw during training, and ideally re-checked periodically, since a model's calibration can drift as the input distribution drifts even while its raw accuracy holds up.
Related concepts
Practice in interviews
Further reading
- Guo, Pleiss, Sun & Weinberger, On Calibration of Modern Neural Networks (2017)
- Niculescu-Mizil & Caruana, Predicting Good Probabilities With Supervised Learning (2005)