7 routes42 sections324 units

Unit 5.4 · about 4 h

163 / 324

Calibration curves and Platt or isotonic recalibration

Thresholds, costs and abstention all read probabilities. An uncalibrated 0.9 is a rumor, not a measurement.

  • implement
  • measure

You can now

  • Read a reliability curve bin by bin and summarize it with ECE without letting one number hide the shape.
  • Fit Platt (sigmoid) and isotonic recalibration on held-out predictions and explain their slope, intercept and monotonicity behavior.
  • Keep a final test split untouched through fitting, calibration and threshold choice.

Covers

  • Calibration curves, slope and intercept at interpretation level
  • Platt and isotonic calibration on held-out predictions

Study, in this order

2 steps

  1. Probability calibration: curves and the calibrator
    scikit-learn - model selection and evaluation route

    Sections 1.16.1 (reliability diagrams via CalibrationDisplay and calibration_curve) and 1.16.2 to 1.16.3 (CalibratedClassifierCV: ensemble averaging versus a single refit, disjoint calibration data)

    Depth · Skip the multiclass example unless your task has more than two classes.

  2. Sigmoid, isotonic and temperature scaling
    scikit-learn - model selection and evaluation route

    Sections 1.16.3.1 (Platt sigmoid: logistic slope and intercept, preserves ranking and AUC), 1.16.3.2 (isotonic: free monotonic steps, stronger past about 1000 points, ties can change AUC) and 1.16.3.4 (temperature scaling)

Focus on

  • Calibrate on predictions the classifier did not train on: CV inside CalibratedClassifierCV, or a disjoint calibration split with FrozenEstimator.
  • In sklearn 1.9, cv=None means 5-fold, stratified when y is binary or multiclass, and ensemble='auto' means an averaging ensemble of per-fold pairs unless the estimator is a FrozenEstimator. Posts written before 1.6 show ensemble=True as the default.
  • Sigmoid fits a logistic slope and intercept: safe on small samples. Isotonic fits a free step function: stronger on large calibration sets, but flat steps tie scores and can move AUC.
  • Lower Brier or log loss does not prove better calibration. Both mix calibration with discrimination, so read the curve.

Reproduce closed-book

Closed-book, simulate overconfident scores: default_rng(1), \(n = 4000\), \(p\) uniform on \([0.05, 0.95]\), \(y\) drawn as \(\operatorname{Bernoulli}(p)\), score \(s = \operatorname{clip}(0.5 + 2.2(p - 0.5), 0.01, 0.99)\). Fit a one-feature logistic (Platt) map on the first 2000 rows and score the last 2000: Brier falls from 0.2130 to 0.1892 (slope 2.80, intercept -1.46 on the raw score). Bin the held-out half with sklearn.calibration.calibration_curve at 5 bins: the top bin predicts 0.964 while 0.776 are positive.

Traps

  • Calibrating on training predictions. Outputs pushed to 0/1 teach the calibrator the wrong map; use CV or a disjoint split.
  • Judging calibration by ECE alone. One number averages away the shape; the user guide warns that lower Brier need not mean better calibrated.
  • Fitting isotonic on a few hundred points and shipping it. It overfits small calibration sets, so prefer sigmoid there.

Practice

Deep-ML 260: Calculate Expected Calibration Error (ECE)

Implement expected_calibration_error and pass both public tests ([0,1] with [0.0,1.0] gives 0.0; four 0.8-probability items with two positives give 0.3)

Use equal-width bins, put \(p = 1.0\) in the last bin, skip empty bins and weight by bin share. Then apply the same function to your Platt experiment above.

Self-test

  1. A bin has mean predicted probability 0.8 with 10 of 40 positives, out of 200 items total. What is its ECE contribution?

  2. Why does isotonic recalibration risk changing AUC while Platt cannot?

  3. What goes wrong if you tune the threshold on the calibration split and report on it too?

  4. GaussianNB probabilities pile near 0 and 1. Sigmoid or isotonic, and on what data?

Completion criterion

Stop when

Your reliability table, ECE function and Platt versus isotonic comparison reproduce on held-out data, and the final test split is still sealed.

Mark passed, then open 5.5 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

  • scikit-learn - model selection and evaluation route
    scikit-learnprimarycourse
    Follow Cross-validation, Hyperparameter tuning, Decision threshold tuning, Metrics and scoring, Probability calibration, Validation curves, Permutation importance and Common Pitfalls. Retain raw predictions and independently hand-check central metrics.

Also in this section

  • ISLP - resampling and multiple testing
    James, Witten, Hastie, Tibshirani and Taylorrequiredtheory
    Use Chapter 5 and the relevant selection-history parts of Chapter 13 with their Python labs. Connect resampling to uncertainty and multiplicity without repeating the full statistics stage.
  • Classical ML Scientific Investigation
    Roadmap-Finalreferenceassessment
    Use Core requirements, architecture constraints, Milestones A-F and failure injection as the standard for end-to-end evidence. The full project remains a later capstone route.
  • D2L - Environment and Distribution Shift
    D2L authorssupporttheory
    Read 4.7, then construct one controlled covariate, label and concept shift. Record what changes, which signal detects it and what response the evidence supports.
  • Deep-ML candidate - evaluation problems
    Deep-MLoptionalpractice
    After the platform admission check, use at most one of 18 K-Fold CV, 260 Expected Calibration Error, 276 ROC, 277 AUC or 840 Stratified K-Fold. Hand-checked local metrics remain the evidence.
  • SciPy - Resampling and Monte Carlo methods tutorials
    SciPy developersreferencereference
    Work the notebooks linked from this page: Tutorial 3 (The Bootstrap) with scipy.stats.bootstrap, including paired=True, and Tutorial 2b (Paired-Sample Permutation Tests) with permutation_test and permutation_type='samples'. Keep one resampling index stream across compared models.
  • El-Yaniv and Wiener - On the Foundations of Noise-free Selective Classification
    JMLRreferencereference
    Read the Abstract and Section 2 (Preliminary Definitions: Definitions 1 and 2 for coverage and selective risk) for the risk-coverage tradeoff. Stop before the noise-free learning bounds.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels