# 置信度校准

置信度校准（confidence calibration）是调整分类器预测概率、使其与预测正确的真实概率相匹配的任务。一个完美校准的模型对任意 \( p \in [0, 1] \) 满足 \( P(\hat{y} = y \mid \hat{p} = p) = p \)：在所有被赋予置信度 \( p \) 的实例中，期望准确率恰好为 \( p \)。<sup>[1](https://papers.nips.cc/paper/2021/file/61f3a6dbc9120ea78ef75544826c814e-Paper.pdf)</sup> 该定义的 top-label 形式仅以最可能类别的概率为条件，由郭川（Chuan Guo）及其同事在《论现代神经网络的校准》（On Calibration of Modern Neural Networks，2017，arXiv）中提出。<sup>[2](https://doi.org/10.48550/arxiv.1706.04599)</sup> 校准不同于准确率：一个模型可以分类得非常好却校准得很差；而温度缩放等校准映射保持预测类别和准确率不变，并且仅当变换后的分数是原始分数的单调函数时（如二分类温度缩放中那样）才保持 ROC AUC 等排序指标，同时改善 Brier 损失和对数损失。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup><sup> • </sup><sup>[4](https://scikit-learn.org/stable/auto_examples/calibration/plot_calibration_curve.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | \( P(\hat{y} = y \mid \hat{p} = p) = p \)；置信度是最大 softmax 输出<sup>[1](https://papers.nips.cc/paper/2021/file/61f3a6dbc9120ea78ef75544826c814e-Paper.pdf)</sup> |
| 典型误校准 | 现代网络在不同数据集和架构上的 ECE 通常在 4% 到 10% 之间<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup> |
| 最简单的修正 | 温度缩放，在 logits 上施加一个标量 \( T > 0 \)，保持准确率<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup> |
| 主要指标 | 期望校准误差（ECE），各分箱中准确率–置信度差距的加权平均<sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup> |
| 指标注意事项 | 分箱 ECE 在统计上是有偏的，对完美校准的模型最为严重<sup>[6](https://proceedings.mlr.press/v151/roelofs22a/roelofs22a.pdf)</sup> |
| 分布偏移行为 | 在 i.i.d. 验证数据上测得的校准在数据集偏移下不再成立；集成方法退化最小<sup>[7](https://proceedings.neurips.cc/paper/2019/file/8558cb408c1d76621371888657d2eb1d-Paper.pdf)</sup> |

## 工作原理

校准通过可靠性图（reliability diagram）来评估，它将期望样本准确率绘制为置信度的函数；一个完美校准的模型位于恒等对角线上。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup> 标准做法是对预测进行分箱并统计结果：为预测值选择若干分箱，然后在每个分箱内将条件事件频率对平均预测值作图。<sup>[8](https://doi.org/10.48550/arxiv.2008.03033)</sup> 在 scikit-learn 中，y 轴的值 \( P(Y=1 \mid \text{predict\_proba}) \) 通过对模型预测概率分箱获得。<sup>[9](https://scikit-learn.org/stable/modules/calibration.html)</sup>

最常见的汇总数字是期望校准误差。预测被划分到 \( M \) 个等间距的分箱中，每个分箱内准确率与平均置信度之间的差距以分箱实例占比为权重进行平均：

\[ \text{ECE} = \sum_{m=1}^{M} \frac{|B_m|}{N} \left| \text{acc}(B_m) - \text{conf}(B_m) \right| \]

其中 \( N \) 是实例数。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup><sup> • </sup><sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup> 最大校准误差（MCE）是最大的分箱差距，\( \max_m |\text{acc}(B_m) - \text{conf}(B_m)| \)；对于完美校准的分类器，两者在总体中均等于 0，尽管有限样本的分箱估计可能非零。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup>

ECE 存在已有记录的缺陷。它仅以预测类别的概率为条件，忽略了其余 \( K-1 \) 个概率；在 CIFAR-10 上其估计值为类条件变体的三分之一，在 ImageNet 上为五分之一。<sup>[10](https://arxiv.org/pdf/1904.01685)</sup> 分箱估计量在统计上是有偏的，矛盾的是对完美校准的模型最为严重<sup>[6](https://proceedings.mlr.press/v151/roelofs22a/roelofs22a.pdf)</sup>，其值随分箱数量大幅变化，且 ECE 不是proper scoring rule：对每个实例返回边际类别分布会产生完美校准但无信息量的预测。<sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup><sup> • </sup><sup>[7](https://proceedings.neurips.cc/paper/2019/file/8558cb408c1d76621371888657d2eb1d-Paper.pdf)</sup>

## 如何实现

事后校准（post-hoc calibration）使用留出验证数据为一个已训练模型学习校准映射，变换其预测以更好地校准。<sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup> 为避免校准器过拟合，普拉特的原始方法将训练数据分为三折，通过交叉验证拟合模型和校准映射。<sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup>

主要的参数方法构成一个通用性递增的家族。Platt 缩放学习标量 \( a, b \in \mathbb{R} \) 并输出 \( \hat{q}_i = \sigma(a z_i + b) \)，在验证集上以负对数似然优化，网络参数保持固定。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup> 温度缩放由同一 2017 年工作提出，将其限制为单个标量：给定 logits \( z_i \)，新置信度为 \( \hat{q}_i = \max_k \sigma_{\mathrm{SM}}(z_i / T)(k) \)，其中 \( T = 1 \) 恢复原始模型，\( T \to \infty \) 趋近均匀概率 \( 1/K \)，\( T \to 0 \) 坍缩为点质量。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup><sup> • </sup><sup>[11](https://proceedings.neurips.cc/paper_files/paper/2019/file/8ca01ea920679a0fe3728441494041b9-Paper.pdf)</sup> 由于 \( T \) 不改变 argmax 类别，准确率不受影响。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup> [等渗回归](https://www.edgepedia.org/zh/isotonic-regression)（isotonic regression）是最常见的非参数替代方法，学习一个分段常数单调函数 \( f \)，\( \hat{q}_i = f(\hat{p}_i) \)；分箱方法倾向于改变类别预测，损害准确率，且在不同设置下不能可靠地改善校准：在现代表格模型上，等渗回归仅在 43.7% 的运行中改善了对数损失（平均变化 +3.22%），Platt 缩放仅为 49.8%；Venn–Abers 获得了最大的平均对数损失降低（-14.17%）。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup> 矩阵缩放和向量缩放原则上可以通过将 logits 作为特征来执行自适应置信度预测，尽管它们在语言建模中容易过拟合。<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2024.emnlp-main.1007.pdf)</sup> Dirichlet 校准推广了两类 beta 校准，可实现为神经网络层或对对数变换概率的多项逻辑回归。<sup>[11](https://proceedings.neurips.cc/paper_files/paper/2019/file/8ca01ea920679a0fe3728441494041b9-Paper.pdf)</sup>

在郭及其同事的基准测试中，温度缩放在视觉任务上优于所有其他方法，在 NLP 数据集上表现相当，尽管其通用性严格低于向量缩放——后者恢复了基本相同的解；网络误校准本质上是低维的。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup> 温度缩放即使在小验证集上也能达到低 ECE，而直方图分箱需要更多验证样本。<sup>[1](https://papers.nips.cc/paper/2021/file/61f3a6dbc9120ea78ef75544826c814e-Paper.pdf)</sup>

## 起源

校准评估早于机器学习：其起源在于天气预报和气象学，二分类情形下的预测置信度评估在 1970 年代已为人知。<sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup> Platt 缩放由约翰·普拉特（John Platt）于 1999 年提出，作为将 SVM 输出从 \( [-\infty, +\infty] \) 变换为后验概率的方法。<sup>[13](https://dl.acm.org/doi/10.1145/1102351.1102430)</sup> 推动重新关注这一领域的现代发现是郭及其同事 2017 年的报告：现代神经网络存在误校准，ECE（15 个分箱）在有和没有跳跃连接的 CNN、循环网络和深度平均网络中通常在 4% 到 10% 之间。<sup>[3](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)</sup> 评估工具包随后得到扩展：尼克斯（Nixon）、杜森伯里（Dusenberry）、张（Zhang）、杰菲尔（Jerfel）、特兰（Tran）及其同事在《测量深度学习中的校准》（Measuring Calibration in Deep Learning，2019）中引入了静态、自适应和阈值自适应校准误差<sup>[10](https://arxiv.org/pdf/1904.01685)</sup>；迪米特里亚迪斯（Dimitriadis）、格奈廷（Gneiting）和乔丹（Jordan）的 CORP 方法（2020）用等渗回归和池相邻违例者算法取代了任意分箱，提供了自动化、无需调参的分箱选择。<sup>[8](https://doi.org/10.48550/arxiv.2008.03033)</sup>

## 变体

对于多于两类的情况，三种定义并存：置信度（top-label）校准、逐类校准（classwise calibration）和强意义下的多类校准，后者包含前两者且是最强的形式。<sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup> 逐类校准要求从模型导出的每个一对其余概率估计器都被校准。<sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup> 多类校准大多通过分解为 \( K \) 个一对其余任务来处理，其归一化预测可能不在多类意义上被校准。<sup>[5](https://link.springer.com/article/10.1007/s10994-023-06336-7)</sup>

这一区分在实践中很重要。温度缩放只有一个可调参数，无法对不同类别采取不同作用，可以是置信度校准的却远非逐类校准的。<sup>[11](https://proceedings.neurips.cc/paper_files/paper/2019/file/8ca01ea920679a0fe3728441494041b9-Paper.pdf)</sup> 在 CIFAR-10 WideResNet 上，温度缩放通过了置信度校准的统计检验，却系统性地高估一个类别、低估另一个类别。<sup>[11](https://proceedings.neurips.cc/paper_files/paper/2019/file/8ca01ea920679a0fe3728441494041b9-Paper.pdf)</sup> 在 21 个数据集和 11 个模型上，Dirichlet 校准在所有 8 项评估指标上最佳或并列最佳，其 ODIR 正则化使矩阵缩放和 Dirichlet 校准在许多深度网络上优于温度缩放。<sup>[11](https://proceedings.neurips.cc/paper_files/paper/2019/file/8ca01ea920679a0fe3728441494041b9-Paper.pdf)</sup> 对于所有基于分箱的估计器，等质量分箱比等宽度分箱更准确地估计真实校准误差。<sup>[6](https://proceedings.mlr.press/v151/roelofs22a/roelofs22a.pdf)</sup>

## 应用

校准方法现在被应用于大语言模型，其中校准意味着缩小置信度分数与以该分数为条件的期望正确性之间的差距，\( \mathbb{E}[f(\mathbf{s} \mid \mathbf{x}) \mid C(\mathbf{x}, \mathbf{s}) = c] = c \)。<sup>[14](https://arxiv.org/html/2503.15850)</sup> 近期文献记录了 LLM 在 RLHF（基于人类偏好反馈训练模型的方法）训练后校准退化的情况。<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2024.emnlp-main.1007.pdf)</sup> 单一温度对 RLHF 后的模型往往失效，因为承载答案的 token 只占序列的一小部分，因此自适应方法根据隐藏特征对每个 token 预测缩放温度。<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2024.emnlp-main.1007.pdf)</sup> [Thermometer](https://www.edgepedia.org/zh/thermometer) 由沈茂浩（Maohao Shen）、达斯（Subhro Das）、格林沃尔德（Kristjan Greenewald）及其同事于 2024 年提出，学习一个辅助模型从无标签数据集预测数据集特定的温度，从而在先前未见过的任务上校准 LLM 的不确定性。<sup>[15](https://doi.org/10.48550/arxiv.2403.08819)</sup> 言语化置信度（verbalized confidence），即模型用语言表述其不确定性，已被探索为另一种对策。<sup>[12](https://aclanthology.org/anthology-files/pdf/emnlp/2024.emnlp-main.1007.pdf)</sup> 评估仍依赖 ECE 变体、MCE、NLL 和 Brier 分数，其中 top-label ECE 作为 ECE 的上界。<sup>[14](https://arxiv.org/html/2503.15850)</sup><sup> • </sup><sup>[16](https://sia.mit.edu/wp-content/uploads/2024/12/2024-shen-das-greenewald-sattigeri-wornell-ghosh-icml.pdf)</sup>

## 局限与替代方案

在 i.i.d. 验证数据上测得的校准不保证在分布偏移下仍然校准：温度缩放的 ECE 随偏移增大而显著增加，引人注目的是其 Brier 分数变得比原始模型更差，因此在验证集上的事后校准可能在偏移下损害校准。<sup>[7](https://proceedings.neurips.cc/paper/2019/file/8558cb408c1d76621371888657d2eb1d-Paper.pdf)</sup> 更好的 i.i.d. 校准和准确率通常不能转化为偏移或分布外数据下更好的校准；集成方法和对模型进行边缘化的方法表现最佳，其中拉克什米纳拉扬（Lakshminarayanan）、普里策尔（Pritzel）和布伦德尔（Blundell）（2016）引入的深度集成是需要从头训练的标准替代方案。<sup>[7](https://proceedings.neurips.cc/paper/2019/file/8558cb408c1d76621371888657d2eb1d-Paper.pdf)</sup><sup> • </sup><sup>[17](https://doi.org/10.48550/arxiv.1612.01474)</sup>

其他局限与测量有关。ECE 的类别盲性、L1 范数和静态分箱意味着减少 ECE 的方法不能仅由 ECE 来恰当评估；在 ImageNet 上优化 \( L_{1} \) 而非 \( L_{2} \) 范数可将测得误差减半。<sup>[10](https://arxiv.org/pdf/1904.01685)</sup> 偏差缩减的 ECE\(_{\mathrm{sweep}}\) 估计器在 70% 的情况下选择最优重校准方法，而标准分箱 ECE 仅为 30%。<sup>[6](https://proceedings.mlr.press/v151/roelofs22a/roelofs22a.pdf)</sup> 训练时正则化仅在特定强度下将平均置信度与准确率对齐，无法实现细粒度校准，最佳系数在不同数据集间差异显著。<sup>[1](https://papers.nips.cc/paper/2021/file/61f3a6dbc9120ea78ef75544826c814e-Paper.pdf)</sup>

## References

1. [Rethinking Calibration of Deep Neural Networks: Do Not Be Afraid of Overconfidence (Chen et al., NeurIPS 2021)](https://papers.nips.cc/paper/2021/file/61f3a6dbc9120ea78ef75544826c814e-Paper.pdf)
2. [Guo, Chuan and colleagues (2017). On Calibration of Modern Neural Networks. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1706.04599)
3. [On Calibration of Modern Neural Networks (Guo, Pleiss, Sun, Weinberger, ICML 2017)](https://proceedings.mlr.press/v70/guo17a/guo17a.pdf)
4. [Probability Calibration curves, scikit-learn documentation](https://scikit-learn.org/stable/auto_examples/calibration/plot_calibration_curve.html)
5. [Classifier calibration: a survey on how to assess and improve predicted class probabilities](https://link.springer.com/article/10.1007/s10994-023-06336-7)
6. [Mitigating Bias in Calibration Error Estimation (Roelofs et al., PMLR v151, 2022)](https://proceedings.mlr.press/v151/roelofs22a/roelofs22a.pdf)
7. [Can you trust your model's uncertainty? Evaluating predictive uncertainty under dataset shift (Ovadia et al., NeurIPS 2019)](https://proceedings.neurips.cc/paper/2019/file/8558cb408c1d76621371888657d2eb1d-Paper.pdf)
8. [Dimitriadis, Timo, Gneiting, Tilmann, Jordan, Alexander I. (2020). Evaluating probabilistic classifiers: Reliability diagrams and score decompositions revisited. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2008.03033)
9. [Probability calibration, scikit-learn documentation](https://scikit-learn.org/stable/modules/calibration.html)
10. [Measuring Calibration in Deep Learning (Nixon et al., 2019)](https://arxiv.org/pdf/1904.01685)
11. [Beyond temperature scaling: Obtaining well-calibrated multi-class probabilities with Dirichlet calibration (Kull et al., NeurIPS 2019)](https://proceedings.neurips.cc/paper_files/paper/2019/file/8ca01ea920679a0fe3728441494041b9-Paper.pdf)
12. [Calibrating Language Models with Adaptive Temperature Scaling (EMNLP 2024)](https://aclanthology.org/anthology-files/pdf/emnlp/2024.emnlp-main.1007.pdf)
13. [Predicting good probabilities with supervised learning (Niculescu-Mizil & Caruana, ICML 2005; ACM DL record, publisher DOI page)](https://dl.acm.org/doi/10.1145/1102351.1102430)
14. [Uncertainty Quantification and Confidence Calibration in Large Language Models: A Survey](https://arxiv.org/html/2503.15850)
15. [Shen, Maohao and colleagues (2024). Thermometer: Towards Universal Calibration for Large Language Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2403.08819)
16. [Thermometer: Towards Universal Calibration for Large Language Models (Shen et al., ICML 2024)](https://sia.mit.edu/wp-content/uploads/2024/12/2024-shen-das-greenewald-sattigeri-wornell-ghosh-icml.pdf)
17. [Lakshminarayanan, Balaji, Pritzel, Alexander, Blundell, Charles (2016). Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1612.01474)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › 机器学习与神经计算 › 机器学习方法

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/confidence-calibration

English original: https://www.edgepedia.org/confidence-calibration
