Recalibration

Recalibration adjusts a model’s predicted probabilities so that they match the rates actually observed. It is a post-processing step: the base model is left alone, a small correction function is fitted on held-out data, and every prediction passes through it on the way out.

The need arises when raw scores are not probabilities or reported probabilities do not match observed rates. An SVM decision margin has a different scale from a probability; boosted trees and neural networks can report probabilities that still require calibration checks. Where the decision is a ranking โ€” show the top thousand, review the riskiest hundred โ€” that is enough. Where the number itself enters a calculation, it is not. A 0.7 that is right 50 percent of the time will not survive contact with an expected-value computation, an insurance premium, or a clinician.

What it does and does not change

For a binary model, the ranking effect depends on the fitted mapping of its scalar score. A sigmoid written as \(\sigma(as+b)\) is strictly increasing when \(a>0\), constant when \(a=0\), and strictly decreasing when \(a<0\). Binary temperature scaling with a positive temperature preserves the score order. Thus ranking preservation requires the increasing case; a negative sigmoid slope reverses the input order. Multi-class transformations need separate analysis, as the table below notes. Isotonic regression is only non-decreasing: it collapses stretches of score to one fitted value, and cases inside such a plateau become tied.

QuantityEffect of recalibration
Ranking, and therefore AUCUnchanged for Platt scaling and for binary temperature scaling when the fitted slope is positive, which makes them strictly increasing in the score. Multi-class temperature scaling preserves each sample’s argmax but not the ordering of one class’s probability across samples. Isotonic regression is non-decreasing rather than strictly increasing, so it ties cases together and AUC can move. How far depends on how much of the score range collapses โ€” a whisker in the measurement below, and more when the fitted function has long plateaus
The class predicted at a fixed quantileUnchanged under a strictly increasing calibrator: the same cases remain the top 5 percent. Isotonic regression can tie cases together at the boundary, and which of the tied cases fall inside the top 5 percent then depends on how the sort breaks ties
The class predicted at a fixed cutoff such as 0.5Can change, because the number that cutoff is compared against has changed. A strictly increasing mapping that fixes the cutoff preserves that decision boundary: for interior probabilities, \(\sigma(2\,\mathrm{logit}\,p)\) fixes 0.5 and preserves the 0.5 selection for every such input. A mapping that moves the boundary can also leave a particular sample unchanged if no case crosses it. Re-evaluate the cutoff against the intended decision rule, and see recalibrate thresholds
Brier score and log lossShould improve if the model was miscalibrated, since the reliability term is what the correction targets. A calibrator fitted on a finite held-out set can still leave the evaluation score unchanged or worse โ€” see the measurement below
Resolution, the model’s ability to separate casesUnchanged under a strictly increasing calibrator, which preserves which cases share a forecast value. Isotonic regression can merge distinct values into one and so reduce it: outcomes 0, 0, 1, 1 predicted at 0.2, 0.2, 0.8, 0.8 have resolution 0.25, and collapsing both groups to 0.5 takes it to 0. Recalibration cannot add information the model did not have, and a non-strict one can discard some

That last row is the honest limit. A strictly increasing recalibration relabels the scale without making the model smarter, and a non-strict one can make it slightly less able to separate cases. A model that cannot tell two groups apart will, after perfect recalibration, assign both the base rate.

Choosing a method

MethodFitsSuited to
Platt scalingTwo parameters, a logistic curveAn S-shaped distortion, which is what over- and underconfidence produce. Works on a few hundred held-out cases
Isotonic regressionA non-decreasing mapping, non-parametric (flat steps at the training points; scikit-learn interpolates linearly between them for new scores)A distortion of any monotone shape. Needs more held-out data and overfits on small sets
Temperature scalingOne parameter, on the logitsMulti-class neural networks. Cannot change which class is predicted
Beta calibrationThree parameters, a beta-family curveScores that are already probabilities and heavily skewed, where the logistic family fits badly

The choice follows the shape of the distortion rather than a rule about sample size. Fit the correction on data the base model has not seen; scikit-learn notes that fitting it on the training data produces “a biased calibrator that maps to probabilities closer to 0 and 1 than it should”, which is the exact opposite of what was wanted.

When it backfires

Recalibration is usually presented as free โ€” worst case, it does nothing. It is not free, and the reason is specific. The sigmoid calibrator in scikit-learn fits a logistic curve to the score \(s\) as \(\sigma(as + b)\). If \(s\) is already a probability, the identity function is not a member of that family, so a correctly calibrated input cannot be left alone. Kull, Silva Filho and Flach put it directly: “the logistic curve family does not include the identity function, and hence logistic calibration can easily uncalibrate a perfectly calibrated classifier.”

Applying both calibrators to a model that needs no correction at all shows the size of it.

import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.isotonic import IsotonicRegression

def ece(y, p, bins=10):
    """Expected calibration error with equal-width bins."""
    edges = np.linspace(0, 1, bins + 1)
    total = 0.0
    for i, (lo, hi) in enumerate(zip(edges[:-1], edges[1:])):
        m = (p >= lo) & (p <= hi) if i == 0 else (p > lo) & (p <= hi)
        if m.any():
            total += m.mean() * abs(p[m].mean() - y[m].mean())
    return total

def already_calibrated(a, b, n=60000, seed=7):
    """Scores that ARE the true probabilities: nothing here needs fixing."""
    rng = np.random.default_rng(seed)
    p = rng.beta(a, b, n)
    return (rng.uniform(size=n) < p).astype(int), p

fit, test = slice(0, 30000), slice(30000, None)
for label, (a, b) in (("symmetric", (2, 2)), ("skewed", (1, 6))):
    y, p = already_calibrated(a, b)
    sig = LogisticRegression().fit(p[fit].reshape(-1, 1), y[fit])
    iso = IsotonicRegression(out_of_bounds="clip").fit(p[fit], y[fit])
    corrected = {
        "none": p[test],
        "sigmoid": sig.predict_proba(p[test].reshape(-1, 1))[:, 1],
        "isotonic": iso.predict(p[test]),
    }
    for name, q in corrected.items():
        print(f"{label:10} {name:9} {float(np.mean((q - y[test]) ** 2)):.4f} {ece(y[test], q):.4f}")
# symmetric  none      0.2024 0.0086
# symmetric  sigmoid   0.2026 0.0128
# symmetric  isotonic  0.2028 0.0123
# skewed     none      0.1047 0.0041
# skewed     sigmoid   0.1056 0.0187
# skewed     isotonic  0.1048 0.0058

The columns are Brier score and ECE. On a symmetric score distribution the damage is small. On the skewed distribution โ€” the common case, and the one Kull and colleagues identify for Naive Bayes and AdaBoost โ€” the sigmoid raises ECE from 0.0041 to 0.0187, more than four times worse, while the Brier score moves from 0.1047 to 0.1056. Isotonic regression, which can represent the identity, barely moves either.

The practical rule this implies is to measure calibration first and evaluate recalibration second. A reliability curve and ECE on held-out data provide evidence, with sampling uncertainty and binning limitations. Compare the fitted correction on separate evaluation data rather than assuming those initial checks guarantee benefit or harm.

Two things recalibration is often asked to do

The first is fixing a cutoff. A spam filter labeled 0.9 on mail that turns out to be spam 70 percent of the time has a scale problem, and recalibration is the right tool โ€” but the threshold that was tuned against the old scale has to move with it. That is a separate operation, covered under recalibrate thresholds.

The second is diagnosis. A single mismatched bin โ€” a group predicted at 0.2 that turns out to occur 30 percent of the time โ€” says the scale is wrong somewhere, and no more than that. Whether the model is overconfident or underconfident depends on which way the error runs above and below the base rate, and one bin cannot answer it. Recalibration corrects both directions with the same machinery, so the diagnosis matters less for the fix than for knowing what went wrong upstream.

References


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.