M2-082M2: Classical Machine LearningModel CalibrationMedium
⚡Flashcard Drill➔Mastery:
Comparing Platt Scaling and Isotonic Regression for Probability Calibration
📐 Mathematical Definition
⚡ One-Sentence Core Answer
Platt scaling fits a parametric sigmoid to model logits; Isotonic regression fits a non-parametric piecewise-constant isotonic step function.
📌 Key Takeaways
- •Platt scaling: parametric logistic regression , robust on small datasets
- •Isotonic regression: non-parametric monotonic step function via Pool Adjacent Violators Algorithm (PAVA)
- •Risk trade-off: Platt scaling assumes sigmoidal calibration curve; Isotonic overfits small sample sizes
📐 Mathematical Derivations
Methodology: ① Platt Scaling: Fits a logistic transformation on uncalibrated model scores : , where parameters are found via maximum likelihood on a held-out calibration set. To prevent overfitting, targets are regularized: . ② Isotonic Regression: Minimizes squared error subject to monotonic order constraints: . Solved exactly in using the Pool Adjacent Violators Algorithm (PAVA).
🏭 Production Trade-offs
Selection criteria: ① Sample Size: When calibration data is small (), use Platt scaling to avoid step-function overfitting. When calibration data is abundant (), Isotonic regression can correct arbitrary monotonic distortions. ② Shape of Distortion: SVM margins typically produce sigmoidal distortion, fitting Platt scaling naturally. Non-sigmoidal distortions (e.g., naive Bayes over-pushing probabilities to 0 and 1) are better corrected by Isotonic regression.
⚠️ Common Interview Pitfalls
- ✕Fitting calibration models on the training dataset rather than an independent validation set
- ✕Using Isotonic regression on very small validation sets, resulting in staircase artifacts and poor generalization
🎯 Interviewer Follow-up Inquiries
- ?How does the Pool Adjacent Violators Algorithm (PAVA) solve isotonic regression in linear time?
- ?Why does Platt scaling apply smoothed target labels rather than hard 0/1 labels during calibration?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
📚
Associated Knowledge Base Guides & Mindmaps
Explore the comprehensive technical article, exam cards, and global architecture tree.
中文速览与面试要点
比较 Platt scaling 与 Isotonic regression
Platt 拟合 sigmoid(参数少、需较少数据);Isotonic 拟合单调阶梯(更灵活但易过拟合)。
核心要点
- Platt scaling 的构造:把模型的原始输出(如 SVM 的决策值或逻辑回归的 logit)作为自变量,用 逻辑回归 拟合真实标签,即 p̂'=σ(a·s+b),其中 a、b 由极大似然在验证集上估计。特点:① 参数少 (仅 2 个)→ 需较少数据(几百样本即可)、不易过拟合;② 假设校准曲线是 sigmoid 形状 (单调 S 形)→ 若真实校准曲线形状更复杂(如非单调、多段),Platt 会欠拟合;③ 通常也 改善了排序 (虽然理论上单调变换不改变排序,但有限数据下拟合会微调)。 Isotonic regression 的构造:拟合一个 单调非减的阶梯函数 ,使 p̂' 与真实标签的平方误差最小(用 PAVA 算法求解)。特点:① 无参数假设 (只要求单调)→ 更灵活、能拟合任意单调校准曲线;② 易过拟合 (阶梯函数在数据少时会'记忆'噪声)→ 需更多数据(建议 >1000 样本);③ 输出是 分段常数 (有平台区),可能不够平滑。
- 选择与要点:① 数据量决定选择 ——小样本( 交叉验证 比较两者在验证集上的 ECE/Brier score。② 校准器需独立数据 ——若用训练集拟合校准器,会因模型在训练集上过拟合(预测过于自信)而使校准器学到错误的映射(把过自信纠正到'训练集上的正确'),在测试集上失效;正确做法是 划分独立的校准集 (或用交叉验证的 out-of-fold 预测)。③ 多分类的校准 ——Platt 可扩展到一对多(每类一个校准器);Isotonic 也可逐类做,但需保证概率和为 1(常需再归一化)。④ 深度网络偏好温度缩放 ——温度缩放(在 softmax 前除以 T)只需 1 个参数、不改变预测类别、对深度网络效果极好,是深度学习的标准校准方法(Hinton 的蒸馏工作即用它)。⑤ 校准与排序的区分 ——校准是单调变换(理论不改变排序),但 有限数据下拟合会引入噪声 ,可能略微改变排序;若任务只需排序,校准非必需。⑥ 评估 ——用 ECE、Brier score、NLL(负对数似然)评估校准效果,而非 accuracy。
- Isotonic 需更多数据且可能过拟合
- 校准必须在独立验证集上拟合
常见陷阱
- 用训练集拟合校准器(失效)
- 在小样本上用 Isotonic(过拟合)