Sub topic 12
Choosing between sigmoid and isotonic calibration
This chapter assumes you know how Platt scaling and isotonic regression work, and that you can use CalibratedClassifierCV. Here the goal is to pick one for a given model and dataset.
The trade-off
Sigmoid calibration fits two parameters. It assumes the miscalibration has a sigmoid shape in the model's score. Isotonic regression fits a step function with many free values. It assumes only that higher scores mean higher probability.
| Property | Sigmoid (Platt) | Isotonic |
|---|---|---|
| Parameters | 2 | Up to one per distinct score |
| Assumption | Sigmoid-shaped distortion | Monotonic distortion |
| Overfitting risk | Low | High on small data |
| Output | Smooth | Piecewise constant, with ties |
| Typical data needed | Hundreds of samples | Thousands of samples |
The sigmoid is biased when the true distortion is not sigmoid-shaped. Isotonic has low bias but high variance. Because it produces ties, it can also reduce ranking quality such as AUC slightly.
Rules of thumb
- Small calibration set (under roughly 1,000 samples): use sigmoid.
- Large calibration set and a clearly non-sigmoid reliability curve: use isotonic.
- Models that push probabilities away from 0 and 1, such as SVMs and boosted trees, usually fit the sigmoid well.
- Models such as naive Bayes, which push probabilities toward 0 and 1, often benefit from isotonic when data is plentiful.
These are starting points. Test them on your own data.
Comparing both methods
Compare the methods by scoring them on data that neither the base model nor the calibrator has seen. Cross-validated Brier score or log loss works well. The code below repeats the comparison at several training sizes to show how the winner can change.
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.calibration import CalibratedClassifierCV
from sklearn.metrics import brier_score_loss
X, y = make_classification(
n_samples=20000, n_features=20, n_informative=5, n_redundant=10, random_state=0
)
X_pool, X_test, y_pool, y_test = train_test_split(
X, y, test_size=0.5, random_state=0
)
for n in (200, 1000, 10000):
X_train, y_train = X_pool[:n], y_pool[:n]
scores = {}
for method in ("sigmoid", "isotonic"):
clf = CalibratedClassifierCV(GaussianNB(), method=method, cv=5)
clf.fit(X_train, y_train)
p = clf.predict_proba(X_test)[:, 1]
scores[method] = brier_score_loss(y_test, p)
print(n, scores)Expect the gap to shrink or reverse as n grows. The exact numbers depend on your scikit-learn version and the data.
Common mistakes
- Choosing the method on the same data the calibrator was fit on. Isotonic will always look better there because it can memorize.
- Judging by expected calibration error alone. ECE depends on binning and is noisy on small test sets, so check Brier score or log loss too.
- Switching to isotonic to fix a model that is already well calibrated. This only adds variance.
Exercise
You have a gradient-boosted model and only 400 held-out samples for calibration. The reliability curve is mildly S-shaped. Which method do you pick, and why?
Show answer
Sigmoid. With 400 samples isotonic regression is likely to overfit, and a mild S-shaped curve is the kind of distortion a two-parameter sigmoid can correct. Confirm with a cross-validated Brier score.