Bin your classifier’s predictions into 10 buckets and build the calibration curve. Then explain how regularization strength reshapes the train/test log-loss curves differently.

The Problem: An L2-regularized logistic regression scores 10,000 held-out examples (43% positive), and at = 0.001, 0.1 and 10 its train log-loss reads 0.29, 0.42 and 0.60 while test log-loss reads 0.52, 0.45 and 0.62. We must bin the predictions into a 10-bucket calibration curve, explain why the two loss curves move differently, and pick the
to ship.
Answer
To build the calibration curve, sort held-out predictions into 10 equal-width bins on [0, 1] and plot each bin’s mean predicted probability against its observed fraction of positives. A calibrated model sits on the diagonal, and the count-weighted mean of the vertical gaps is the expected calibration error (ECE). Regularization strength reshapes the two log-loss curves differently: train log-loss rises monotonically with , while test log-loss is U-shaped. On the weak side, overconfident probabilities let a few confident mistakes dominate the unbounded log term, and the calibration curve flattens below the diagonal at high scores. On the strong side, predictions shrink toward the base rate, the curve turns steeper than the diagonal, and both losses converge on the base-rate entropy (0.68 nats at 43% positives).
(1) Binning Recipe: Cut [0, 1] into ten intervals of width 0.1, assign each held-out prediction to one, and record the count, the mean predicted probability, and the observed positive rate per bin. Plot rate against mean and print the counts, because a 30-point bin is mostly noise.
(2) Reading The Shape: A curve flatter than the diagonal (above it at low scores, below it at high scores) means overconfidence, and a curve steeper than the diagonal means underconfidence. The overall mean can match the base rate while both tails are wrong.
(3) ECE And Its Noise: ECE weights each gap by the bin’s share of the data. Each observed rate carries a standard error of about , so a 0.01 gap in a 400-point bin is noise while a 0.12 gap in a 2,200-point bin is roughly 15 standard errors.
(4) Train Loss Is Monotone: The data term of the regularized optimum is nondecreasing in , so train log-loss only rises as the penalty grows, from near zero on separable data toward the base-rate entropy.
(5) Test Loss Is An Asymmetric U: The weak- arm is steep and unbounded, since one miss at
costs 4.6 nats. The strong-
arm is gentle and capped at
, and the train/test gap narrows as
grows.
(6) Log-Loss Bends Before Accuracy: Accuracy only checks which side of 0.5 a score lands on, so it can stay flat while probabilities degrade. Choose on held-out log-loss whenever the probabilities themselves feed decisions.
Mathematical Formulation:
Where:
is the m-th of
equal-width intervals (the last one also includes 1), and
is the set of test examples whose prediction
falls in it, with count
.
indexes the
test examples, each with label
.
and
are the bin’s mean predicted probability and observed positive rate; plotting acc against conf for every non-empty bin gives the reliability diagram.
is the count-weighted mean absolute gap, lying in
.
is the per-example log-loss in nats,
is the logistic function,
are the weights, and
is the unpenalized intercept.
is mean log-loss on split
, measured without the penalty. The two curves are
and
evaluated at the minimizer of
, where
is the L2 strength (scikit-learn’s
plays the inverse role).
is the true positive rate among examples that receive score
. The binary
is the calibration term (zero only when calibrated), and the binary entropy
is the refinement term (small when scores separate the classes).
is the base rate, and
equals 0.68 nats at
: the loss of predicting the base rate for everyone, which a fully shrunk model with a free intercept approaches.
Worked Example:
Take the model on the 10,000 test points. The table lists each bin’s count, mean predicted probability, and observed positive rate, and each ECE share is
times the absolute gap. The top bin holds 2,200 predictions averaging 0.96 that are right only 84% of the time, contributing 0.0264 on its own. The bottom bin’s 3,500 predictions at 0.04 turn out positive 10% of the time. Summing the ten shares gives ECE = 0.0748, with both tails off in the overconfident direction. Yet the mean prediction, 0.440, sits close to the 0.428 base rate, so a single global check would have passed this model.
| Bin | Range | Count | Mean predicted | Observed rate | Gap | ECE share |
|---|---|---|---|---|---|---|
| 1 | [0.0, 0.1) | 3,500 | 0.04 | 0.10 | 0.06 | 0.0210 |
| 2 | [0.1, 0.2) | 900 | 0.15 | 0.22 | 0.07 | 0.0063 |
| 3 | [0.2, 0.3) | 500 | 0.25 | 0.30 | 0.05 | 0.0025 |
| 4 | [0.3, 0.4) | 400 | 0.35 | 0.38 | 0.03 | 0.0012 |
| 5 | [0.4, 0.5) | 400 | 0.45 | 0.46 | 0.01 | 0.0004 |
| 6 | [0.5, 0.6) | 300 | 0.55 | 0.53 | 0.02 | 0.0006 |
| 7 | [0.6, 0.7) | 400 | 0.65 | 0.60 | 0.05 | 0.0020 |
| 8 | [0.7, 0.8) | 500 | 0.75 | 0.66 | 0.09 | 0.0045 |
| 9 | [0.8, 0.9) | 900 | 0.85 | 0.74 | 0.11 | 0.0099 |
| 10 | [0.9, 1.0] | 2,200 | 0.96 | 0.84 | 0.12 | 0.0264 |
| Total | [0, 1] | 10,000 | 0.440 | 0.428 | weighted | 0.0748 |
Regularization acts on the two loss curves through different mechanisms. On the training set, any extra penalty can only trade fit for smaller weights, so train log-loss climbs from 0.29 at to 0.60 at
with no turning point. On the test set, a small
lets
grow until the logits saturate. Predictions then crowd 0 and 1, and every confident miss costs
, already 3.2 nats at
. A large
shrinks the logits toward the intercept, so predictions bunch around the 43% base rate and both losses rise toward
because the model has stopped separating the classes. The two arms are therefore not mirror images. The left arm is overconfidence and variance and can climb without bound, while the right arm is underfitting and is capped at 0.68 nats. Accuracy hides most of this:
and
differ by 0.4 accuracy points but by 0.07 nats of test log-loss.

Figure 1: (a) Ten-bin reliability diagrams, marker area proportional to bin count. is flatter than the diagonal (ECE 0.075),
is steeper and packed into 0.27 to 0.62 (ECE 0.083), and
tracks the diagonal (ECE 0.010). (b) Train log-loss rises monotonically while test log-loss is an asymmetric U with its minimum near
. Both approach
, and the curves interpolate the three measured settings.
Leave a Reply