Skip to content

Expected calibration error

Calculate a binned probability-calibration error, distinguish positive-class from top-label ECE, and see how bin boundaries can change the result.

Expected calibration error (ECE) summarises mismatches between predicted probabilities and observed event frequencies by averaging absolute gaps across probability bins, weighted by the number of predictions in each bin. For a quant model feeding probabilities into position sizing, it asks whether the numbers behave like frequencies. A small ECE alone cannot establish that the model is useful or safe to size from.

First name the probability being checked

There are different ECE conventions. This article's worked example checks binary positive-class probabilities: pip_i estimates P(Yi=1∣Xi)\mathbb{P}(Y_i=1\mid X_i), and yiy_i is the realised zero-or-one outcome. Probability calibration means that among forecasts near pp, the positive event occurs with frequency near pp. This is the positive-instance formulation in Naeini et al. (2015).
The widely used top-label ECE in Guo et al. (2017) instead bins the probability assigned to the predicted class and compares it with classification accuracy. In binary classification, that confidence is ci=max⁡(pi,1−pi)c_i=\max(p_i,1-p_i); the outcome being averaged becomes 1{y^i=yi}\mathbf{1}_{\{\hat y_i=y_i\}}. For pi=0.2p_i=0.2, the positive-class probability is 0.20.2, while confidence in the predicted class 0 is 0.80.8. State the class-selection and tie rules when calculating top-label ECE. These two inputs and outcomes must not be silently interchanged. In multiclass problems, top-label ECE also omits the other class probabilities.

A weighted gap, not a classification error rate

For nonempty bins BmB_m containing nmn_m of the nn observations, define

pˉm=1nm∑i∈Bmpi,yˉm=1nm∑i∈Bmyi.\bar p_m=\frac{1}{n_m}\sum_{i\in B_m}p_i, \qquad \bar y_m=\frac{1}{n_m}\sum_{i\in B_m}y_i.

The empirical positive-class score is

ECE^+=∑m:nm>0nmn∣yˉm−pˉm∣.\widehat{\mathrm{ECE}}_{+} =\sum_{m:n_m>0}\frac{n_m}{n}\lvert\bar y_m-\bar p_m\rvert.
An empty bin contributes zero. The absolute value is taken after averaging within each bin. Averaging ∣yi−pi∣\lvert y_i-p_i\rvert observation by observation measures something different. This weighted-bin construction follows Naeini et al., “Calibration Measures”.

Consider ten fictional forecasts of a positive financial event, with a fixed event definition and horizon:

Observation12345678910
Predicted pip_i0.10.20.30.40.50.60.70.80.91.0
Realised yiy_i0010101101

Use bins [0,0.5)[0,0.5) and [0.5,1][0.5,1], explicitly including 1 in the upper bin.

BinCountMean probabilityPositive frequencyWeighted absolute gap
[0,0.5)[0,0.5)40.251/4=0.251/4=0.250
[0.5,1][0.5,1]60.754/6=2/34/6=2/30.05

Hence

ECE^+=410∣0.25−0.25∣+610∣23−0.75∣=0.05.\widehat{\mathrm{ECE}}_{+} =\frac{4}{10}|0.25-0.25| +\frac{6}{10}\left|\frac{2}{3}-0.75\right| =0.05.
That is a five-percentage-point weighted calibration gap, not “5% of labels predicted incorrectly,” and not a claim that every forecast is within five points of its true probability.
Original fictional example. The vertical distance from each point to the diagonal is its bin gap; ECE weights those gaps by bin counts. Changing the endpoint rule changes the summary without changing a forecast or outcome.

Move only the endpoint convention to [0,0.5][0,0.5] and (0.5,1](0.5,1]. The forecast at 0.50.5 moves into the lower bin. Counts become 5 and 5; mean probabilities become 0.30.3 and 0.80.8; positive frequencies become 0.40.4 and 0.60.6. The score is now

510∣0.4−0.3∣+510∣0.6−0.8∣=0.15.\frac{5}{10}|0.4-0.3|+\frac{5}{10}|0.6-0.8|=0.15.

The model has not changed. The reported ECE has tripled because the bin definition changed. These are intentionally tiny teaching data, not evidence of model quality.

INTERACTIVE EXPLORER

Binary probability calibration

Change probability bins and inspect the weighted calibration gap.

What the scalar can hide

Cancellation inside a bin. Consider a separate fictional sample with two equally sized groups: one predicts 0.20.2 and has positive frequency 0.40.4; the other predicts 0.80.8 and has positive frequency 0.60.6. Pool them into one bin and both averages are 0.50.5, giving ECE zero. Separate the groups and ECE is 0.20.2. Underprediction and overprediction cancelled before the absolute value. Nixon et al., Sections 3.3–3.4 discuss this masking and the tradeoff between finer bins and noisier bin estimates.
Estimation is not population truth. The population quantity for this binary variant is E[∣E[Y∣P]−P∣]\mathbb{E}[|\mathbb{E}[Y\mid P]-P|], where PP is the model's probability forecast. A finite binned estimate adds sampling noise and aggregation effects. Holding a coarse partition fixed need not recover that quantity even with many observations; finite-sample ECE is not guaranteed to be a lower bound. Vaicenavicius et al., Sections 4.1–4.3 distinguish these asymptotic and sampling issues.
Calibration is not all predictive quality. A constant forecast equal to the population event rate can be calibrated while ignoring useful information in XX. ECE is a calibration diagnostic, not a proper scoring rule for individual forecasts. It cannot replace a predictive loss that rewards truthful conditional probabilities. Report Brier score or log loss alongside calibration, ranking and decision-relevant evaluation. Proper-loss training itself does not guarantee calibration on new data; see Nixon et al., Section 2.2.

Use it as an audit trail

Report the variant, event label and horizon, evaluation sample size and period, bin edges and endpoint rules, bin counts, and each bin's signed gap. A calibration curve shows where the scalar comes from. Keep binning conventions consistent when comparing models and assess sensitivity to reasonable alternatives.

Fit any recalibration map on training or calibration data, then evaluate it on separate held-out outcomes. Repeatedly choosing a calibrator or bins to minimise the final test ECE makes that test part of model selection. For financial time series, respect chronology and overlapping label windows; an overall score can also conceal failures in important regimes. The owned Probability calibration lesson connects these validation choices to sizing inputs; its full teaching requires membership, with a public preview.

Sources

Last updated
  • calibration
  • model validation
  • classification
  • probability forecasts
← Back to the glossaryBack to top ↑