research29 min studyLesson 864 in Engineering

Calibration by class and subpopulation

Expose cancellation of calibration gaps across classes and groups while reporting bin definitions, counts, and sampling uncertainty.

On this page

What you’ll understand

  • Distinguish top-label, classwise, and subgroup calibration targets.
  • Construct an aggregate calibration example that hides opposing group gaps.
  • Design slice measurements without treating sparse bins or discovery as final evidence.

A service can report 80% confidence and be correct on 80% of cases overall while substantially overstating its reliability for one group and understating it for another. Averaging can cancel errors before a headline metric is computed. Calibration therefore needs a named target: probability of a particular class, correctness of the predicted class, or a probability conditional on a specified population. These targets support different conclusions and require different denominators.

Define the outcome and conditioning information

For top-label calibration, confidence is the largest predicted class probability and the outcome is whether the chosen label is correct. Classwise calibration instead compares the probability assigned to class j with the indicator that the true label is j, including cases where j was not predicted. A model can satisfy one condition without satisfying the other. Reliability plots must state which outcome they use; a plot titled calibration with no target cannot establish the property needed by a downstream decision.

Adding group membership to the conditioning event is a stronger requirement than matching an aggregate curve. Groups may be languages, acquisition devices, workload types, or overlapping intersections selected for a task-specific reason. Membership information and labels must have clear provenance. Missing labels, delayed outcomes, or noisy annotations can distort apparent group gaps, especially if the observation process differs between accepted and rejected cases. Measure support and label quality before interpreting the gap as solely a model probability error.

P(Y=j∣p^j(X)=p,G=g)=p\mathbb P(Y=j\mid \widehat p_j(X)=p,G=g)=p
This is an ideal classwise, group-conditional calibration target for positive-probability conditioning events, interpreted using regular conditional distributions where needed. Probabilities are dimensionless. Empirical bins approximate it and cannot prove the equality at every p or every group from finite data.↔ Scroll wide equations horizontally.

Aggregate metrics can erase opposite errors

Suppose every case has the same reported confidence but two equal-sized groups have different correctness rates. Their aggregate correctness can equal the common confidence exactly, while both groups have substantial gaps of opposite signs. Computing the absolute aggregate gap after pooling differs from computing an average of absolute group gaps. This is an arithmetic cancellation, not a paradox, and it persists even if the grouped labels are perfectly reliable and the sampling noise is small.

Binned expected calibration error also changes with the binning scheme, sample allocation, and definition of confidence. Report bin edges, counts, mean scores, empirical frequencies, and uncertainty alongside the scalar summary. Adaptive bins and many searched intersections create additional selection effects. Use development data to discover candidate failure slices and separate data to confirm them, or apply an analysis that accounts for the search. Multicalibration studies richer collections of subpopulations; its guarantees are specific to the collection, tolerances, and assumptions actually used.

ECE⁡^=∑b=1BnbN∣1nb∑i∈bci−1nb∑i∈b1{y^i=yi}∣\widehat{\operatorname{ECE}}=\sum_{b=1}^{B}\frac{n_b}{N}\left|\frac{1}{n_b}\sum_{i\in b}c_i-\frac{1}{n_b}\sum_{i\in b}\mathbf 1\{\widehat y_i=y_i\}\right|
This is empirical top-label ECE for a declared partition into nonempty bins b, confidence c_i, and N total cases. It is dimensionless and depends on the partition. Empty bins contribute no term; the statistic is not a distribution-free bound on group-conditional calibration.↔ Scroll wide equations horizontally.

Make slice evidence usable to a policy

Do not interpret calibration as a complete fairness or utility criterion. Two calibrated groups can still have different error rates or encounter different consequences from the same action. Conversely, changing thresholds to meet a policy objective changes which cases receive decisions and can alter the operational distribution. Evaluate the policy’s relevant losses, coverage, and delay by group, retaining the original probability evaluation. When data are scarce, report uncertainty and unresolved support rather than silently treating an empty slice as calibrated.

The sampling lab illustrates count uncertainty under a declared common rate, not group calibration fitting. Reset, set p to 0.8 and n to 20, predict sample-mean variance 0.008, then Step. Compare a fresh Reset with both p at 0.8 and n at 100 before Step: variance 0.0016. The exact Bernoulli sampling distribution becomes narrower under independence. It does not identify real groups, discover biased labels, or prove that the supplied probability equals any deployment group’s correctness rate.

A perfect aggregate bin with two imperfect groups

One confidence bin contains 50 cases from group A and 50 from group B, all reported at confidence 0.8. The classifier is correct on 45 A cases and 35 B cases. Compute aggregate and group calibration gaps for this observed sample.

  1. Group A accuracy is 45/50 = 0.9, so confidence minus accuracy is −0.1. Group B accuracy is 35/50 = 0.7, giving a gap of +0.1.

  2. Pooled accuracy is (45 + 35)/100 = 0.8. The single aggregate bin has absolute gap zero, despite both observed group gaps having magnitude 0.1.

  3. An equal-weight average of absolute group gaps is (0.1 + 0.1)/2 = 0.1. Neither observed statistic alone removes finite-sample uncertainty or establishes behavior outside this bin.

The result

Pooling before taking the absolute value can hide group-specific errors with opposite signs.

Explore the model

Interactive lab

Interactive lab · sampling

Slice size changes uncertainty in an observed rate

Reset, set p = 0.8 and n = 20, predict sample-mean variance 0.008, then Step. Compare a fresh Reset with both p = 0.8 and n = 100 before Step: variance 0.0016. This exact independent-Bernoulli instrument assumes its rate; it does not fit or validate subgroup calibration.

Slice size changes uncertainty in an observed rateExact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Current readings: Mean sample proportion: 0.5; Sample-mean variance: 0.0125; Uniform CDF error bound: ≤ 0.1062. All parameters are adjustable with the labeled controls below.Exact distribution of the mean of 20 independent Bernoulli variables with success probability 0.5; playback highlights outcome 0.00.250.50.75100.0580.1150.1730.23Sample mean · k / nProbability massNormal bin masses are an approximationk = 0 · exact probability = 9.54e-7
Exact binomial massNormal interval massHighlighted outcome / mean
Mean sample proportion
0.5
Sample-mean variance
0.0125
Uniform CDF error bound
≤ 0.1062
t = 0 s

Exact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA small observed gap and a well-supported calibration claim are different kinds of evidence.

Check your understanding

A single pooled confidence bin is perfectly calibrated in the observed sample. Which additional conclusion is justified?

Try it yourself

All 100 cases have confidence 0.7. Group A has 80 cases with 60 correct; group B has 20 with 10 correct. Compute the pooled absolute gap and the size-weighted mean absolute group gap.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Compute each group accuracy first. Pooling signed gaps and averaging absolute group gaps are different operations.

Compare with the solution

The pooled accuracy is 70/100 = 0.7, so its absolute gap is zero. Group A accuracy is 0.75 and its absolute gap is 0.05; group B accuracy is 0.5 and its gap is 0.2. The weighted mean absolute group gap is 0.8 × 0.05 + 0.2 × 0.2 = 0.08. Group B’s smaller sample also warrants greater uncertainty attention; the zero aggregate gap does not resolve its observed mismatch.

Take it with you

  • Name the calibration target and every conditioning population.
  • Aggregating signed gaps can conceal substantial group mismatches.
  • Report slice support, label quality, and selection-aware uncertainty with the metric.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.