# 贝叶斯分类器

贝叶斯分类器是一种分类方法：给定输入的特征，它用贝叶斯定理计算后验概率，并把输入判给后验概率最高的类。它是理论最优：在所有可能的分类器中，它的误分类概率最小，因此其错误率——贝叶斯错误率——是其他任何分类器都无法击穿的下限。<sup>[1](https://papers.neurips.cc/paper_files/paper/2021/file/4e0ccd2b894f717df5ebc12f4282ee70-Paper.pdf)</sup><sup> • </sup><sup>[2](https://booksite.elsevier.com/samplechapters/9780123744869/02~Chapter_1.pdf)</sup> 理想分类器几乎无法直接计算，因为它需要关于数据分布的完整知识；但它为理论与实践提供了锚点：其错误率衡量一项任务的难度。<sup>[1](https://papers.neurips.cc/paper_files/paper/2021/file/4e0ccd2b894f717df5ebc12f4282ee70-Paper.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 决策规则 | 将 x 判为 \( \arg\max_{y} P(y \mid x) \)，等价地判为 \( \arg\max_{y} P(x \mid y) P(y) \)<sup>[3](https://www.cs.cornell.edu/courses/cs3780/2025sp/lectures/lecturenote05.html)</sup> |
| 贝叶斯错误率 | \( \mathbb{E}_{x}\{1 - \max_{i} P(C_{i} \mid x)\} \)，该问题上可实现的最小错误<sup>[4](https://ar5iv.labs.arxiv.org/html/2501.07754)</sup> |
| 等价关系 | 最优分类器是最大后验（MAP）分类器；在先验均匀时，它退化为最大似然<sup>[5](https://proceedings.neurips.cc/paper_files/paper/2023/file/647e122fc406573c51276692f20379b5-Paper-Conference.pdf)</sup><sup> • </sup><sup>[6](https://www.cs.jhu.edu/~ayuille1/JHUcourses/VisionAsBayesianInference2024/5/Lecture5BayesDecisionTheory.pdf)</sup> |
| 朴素贝叶斯假设 | 给定类别时特征条件独立：\( P(x \mid y) = \prod_{\alpha=1}^{d} P(x_{\alpha} \mid y) \)<sup>[3](https://www.cs.cornell.edu/courses/cs3780/2025sp/lectures/lecturenote05.html)</sup> |
| 参数节省 | 独立性将待估参数从 \( 2(2^{n} - 1) \) 个减少到 \( 2n \) 个<sup>[7](http://www.cs.cmu.edu/%7Etom/mlbook/NBayesLogReg.pdf)</sup> |
| 样本复杂度 | 朴素贝叶斯以 \( O(\log n) \) 个样本逼近其渐近错误率，而逻辑回归需要 \( O(n) \) 个样本，其中 n 为特征维数<sup>[8](https://doi.org/10.48550/arxiv.2302.02334)</sup> |
| 每次观测成本 | 对 t 个训练观测，训练成本为 \( O(t \cdot P) \)；对一个观测分类的成本为 \( O(m \cdot P) \)，其中 m 为类别数，P 为特征数<sup>[9](https://pmc.ncbi.nlm.nih.gov/articles/PMC4832935/)</sup> |

## 如何工作

分类器输出一个类别标签。对观测 x，它计算每个类的后验概率 \( P(y \mid x) \)，并预测后验概率最大的类。对两类 \( w_{1} \) 与 \( w_{2} \)，规则是：若 \( P(w_{1} \mid x) > P(w_{2} \mid x) \)，则将 x 判为 \( w_{1} \)，否则判为 \( w_{2} \)。<sup>[10](https://www.cs.man.ac.uk/~fumie/tmp/bayesclassifier.pdf)</sup>

[贝叶斯定理](https://www.edgepedia.org/zh/bayes-theorem)将后验改写为 \( P(y \mid x) = P(x \mid y) P(y) / P(x) \)。由于 \( P(x) \) 对每个类都相同，决策简化为最大化 \( P(x \mid y) P(y) \)，即类条件密度与先验的乘积。<sup>[3](https://www.cs.cornell.edu/courses/cs3780/2025sp/lectures/lecturenote05.html)</sup> 在同等惩罚所有错误的损失下，这种最大后验选择正是最大后验（MAP）决策；若先验均匀，则进一步简化为最大似然选择 \( \arg\max_{y} P(x \mid y) \)。<sup>[6](https://www.cs.jhu.edu/~ayuille1/JHUcourses/VisionAsBayesianInference2024/5/Lecture5BayesDecisionTheory.pdf)</sup>

为什么这能最小化错误：分类器的风险为 \( R(h) = P[h(X) \neq Y] \)，即其错误概率。在每个 x 处选择后验 \( \eta_{y}(x) \) 最大的类，会逐点最小化该概率；因此对任何其他分类器 h，\( R(h) \geq R(h^{\star}) \)。<sup>[11](https://mdav.ece.gatech.edu/ece-6254-spring2024/notes/03-notes-6254-sp24.pdf)</sup>

## 如何实现

真实后验未知，因此实际中的贝叶斯分类器是插入式分类器：从训练数据估计先验与类条件密度，再将估计值代入决策规则。<sup>[12](https://web.eecs.umich.edu/~cscott/past_courses/eecs598w14/notes/02_bayes_classifier.pdf)</sup><sup> • </sup><sup>[13](https://wiki.eecs.yorku.ca/course_archive/2016-17/F/6327/_media/ml4-decision-rule.pdf)</sup> 先验通常估计为类频率；未知先验 \( \pi_{k} \) 可估计为 \( n_{k}/n \)。<sup>[14](https://rich-d-wilkinson.github.io/MATH3030/6.2-lda-Bayes.html)</sup>

估计 \( p(x \mid y) \) 有两条路线。参数模型为每类拟合一个分布族，例如高斯分布：在共享协方差 \( \Sigma \) 下，贝叶斯判别规则成为线性规则 \( \delta_{k}(x) = \mu_{k}^{\top} \cdot \Sigma^{-1} \cdot x - \tfrac{1}{2} \mu_{k}^{\top} \cdot \Sigma^{-1} \cdot \mu_{k} + \log \pi_{k} \)（线性判别分析，在 R 的 MASS 库中实现为 lda 命令）；而类特定协方差 \( \Sigma_{k} \) 给出二次决策边界（QDA）。

## 变体

完整贝叶斯分类器需要所有特征的联合分布，这在高维中难以处理。朴素贝叶斯分类器假设给定类别值时每个属性独立于其余属性，因此 \( \Pr(A_{1}, \ldots, A_{k} \mid C) = \Pr(A_{1} \mid C) \Pr(A_{2} \mid C) \cdots \Pr(A_{k} \mid C) \)。<sup>[15](https://ai.stanford.edu/~ronnyk/bayesHB.pdf)</sup><sup> • </sup><sup>[16](https://www.cs.ubc.ca/~murphyk/Teaching/CS340-Fall06/reading/NB.pdf)</sup> 这将待估参数从 \( 2(2^{n} - 1) \) 个减少到 \( 2n \) 个，决策规则变为 \( \hat{y} = \arg\max_{y} P(y) \prod_{i=1}^{n} P(x_{i} \mid y) \)，实践中按对数项之和计算。<sup>[7](http://www.cs.cmu.edu/%7Etom/mlbook/NBayesLogReg.pdf)</sup><sup> • </sup><sup>[3](https://www.cs.cornell.edu/courses/cs3780/2025sp/lectures/lecturenote05.html)</sup>

变体与特征类型相匹配：多项式朴素贝叶斯为文本统计词出现次数；伯努利朴素贝叶斯使用二元指示变量，且与多项式变体不同，会显式惩罚指示特征未出现。<sup>[17](https://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html)</sup><sup> • </sup><sup>[18](https://scikit-learn.org/stable/modules/naive%5Fbayes.html)</sup> 独立性假设通常是假的，但朴素贝叶斯仍保持稳健：只要正确类仍具有最高后验概率，零一损失就不会惩罚不正确的后验估计。<sup>[9](https://pmc.ncbi.nlm.nih.gov/articles/PMC4832935/)</sup><sup> • </sup><sup>[15](https://ai.stanford.edu/~ronnyk/bayesHB.pdf)</sup> 作为折中，成对朴素贝叶斯（PNB）分类器纳入属性之间的所有成对关系，而无需指定联合分布；在其已发表应用中，使用正态密度估计时，它在具有连续属性的数据集上给出了最高准确率。<sup>[9](https://pmc.ncbi.nlm.nih.gov/articles/PMC4832935/)</sup>

## 起源

其思想谱系反而有文献记载。将最优性作为一个有意的统计纲领，是由内曼-皮尔逊引理确立的；该引理确立了似然比检验对简单假设具有最大功效。<sup>[19](https://www.stat.rice.edu/~tsn4867/all_files/IMS_VOLUME/LEHMANN/Lehmann_hist_opt.pdf)</sup> [亚伯拉罕·沃尔德](https://www.edgepedia.org/zh/abraham-wald)（Abraham Wald）在其 1939 年论文《对统计估计与检验理论之贡献》（“Contributions to the Theory of Statistical Estimation and Testing Hypotheses”）中开启了一条不同的决策论路径，该文发表于《数理统计年鉴》（The Annals of Mathematical Statistics），并在随后一系列出版物中进一步发展，包括他 1949 年发表于《数理统计年鉴》的文章《统计决策函数》（“Statistical Decision Functions”）以及 1950 年的同名著作；沃尔德将在备择假设上的权重函数下最大化平均功效的程序称为“贝叶斯解”。<sup>[19](https://www.stat.rice.edu/~tsn4867/all_files/IMS_VOLUME/LEHMANN/Lehmann_hist_opt.pdf)</sup><sup> • </sup><sup>[20](https://doi.org/10.1214/aoms/1177732144)</sup><sup> • </sup><sup>[21](https://doi.org/10.1214/aoms/1177730030)</sup> 20 世纪 30 年代的内曼-皮尔逊与沃尔德决策论学派后来被纳入贝叶斯框架。<sup>[22](https://unina2.on-line.it/sebina/repository/catalogazione/documenti/Dale%20-%20A%20history%20of%20inverse%20probability%20from%20Thomas%20Bayes%20to%20Karl%20Pearson.pdf)</sup> 到 1968 年，模式识别综述将基于似然的分类形式化，并指出在先验相等时只需比较类条件密度。<sup>[23](https://sites.ecse.rpi.edu/~nagy/PDF_chrono/1968_Nagy_Classification_IEEE_Audio_68.pdf)</sup> 2001 年，吴恩达（Andrew Y. Ng）和[迈克尔·I·乔丹](https://www.edgepedia.org/zh/michael-i-jordan)（Michael I. Jordan）针对二分类证明，朴素贝叶斯与逻辑回归处于不同的样本复杂度区间；2023 年，郑晨宇（Chenyu Zheng）及其同事在温和假设下将该结果推广到多类朴素贝叶斯与逻辑回归。<sup>[8](https://doi.org/10.48550/arxiv.2302.02334)</sup>

## 应用

朴素贝叶斯分类器尽管假设简化，在许多现实场景中表现良好，最著名的是文档分类和垃圾邮件过滤，而且只需少量训练数据。<sup>[18](https://scikit-learn.org/stable/modules/naive%5Fbayes.html)</sup> 垃圾邮件过滤是一个标准设定，尽管“给定是否为垃圾邮件时词条件独立”这一假设显然为假；所得分类器仍能表现良好。<sup>[3](https://www.cs.cornell.edu/courses/cs3780/2025sp/lectures/lecturenote05.html)</sup> 理想贝叶斯分类器本身可作为基准：因为贝叶斯错误率衡量任务的难度，训练好的模型会以它为参照进行评估。<sup>[1](https://papers.neurips.cc/paper_files/paper/2021/file/4e0ccd2b894f717df5ebc12f4282ee70-Paper.pdf)</sup>

在郑等人（2023）的假设下，多类朴素贝叶斯的分类错误率以 \( O(\log n) \) 个样本逼近其渐近错误率，其中 n 是特征维数；而多类逻辑回归需要 \( O(n) \) 个样本；在该结果覆盖的区间内，训练数据稀缺时朴素贝叶斯占优，而有许多样例时逻辑回归往往占优。<sup>[8](https://doi.org/10.48550/arxiv.2302.02334)</sup> 在计算上，类条件特征分布解耦为可独立估计的一维分布，这使朴素贝叶斯学习器极快，并缓解维数灾难。<sup>[18](https://scikit-learn.org/stable/modules/naive%5Fbayes.html)</sup>

## 局限与替代方案

理想贝叶斯分类器几乎无法直接使用。它需要后验 \( \eta_{y}(x) \) 的完整知识，这在机器学习中不是一个合理假设；而精确计算贝叶斯错误率几乎总是难以处理，因为它需要分布的完整知识。<sup>[11](https://mdav.ece.gatech.edu/ece-6254-spring2024/notes/03-notes-6254-sp24.pdf)</sup><sup> • </sup><sup>[1](https://papers.neurips.cc/paper_files/paper/2021/file/4e0ccd2b894f717df5ebc12f4282ee70-Paper.pdf)</sup> 对 \( P(y,x)/P(x) \) 的直接最大似然估计在高维中失败，因为相同特征向量从不会出现；这促使人们生成式地估计 \( P(y) \) 和 \( P(x \mid y) \)。<sup>[3](https://www.cs.cornell.edu/courses/cs3780/2025sp/lectures/lecturenote05.html)</sup> 联合分布要求还使完整分类器在计算上难以处理，会出现极小的样本概率以及无法估计的测试观测；使用拉普拉斯估计来避免零概率估计，零计数概率可替换为一个小常数，如 \( 0.5/n \) 或 \( \Pr(C)/n \)。<sup>[9](https://pmc.ncbi.nlm.nih.gov/articles/PMC4832935/)</sup><sup> • </sup><sup>[15](https://ai.stanford.edu/~ronnyk/bayesHB.pdf)</sup>

校准是另一个问题。朴素贝叶斯以“不错的分类器、糟糕的估计器”著称，因此其概率输出不应过于当真。<sup>[18](https://scikit-learn.org/stable/modules/naive%5Fbayes.html)</sup> 概率分类器在预测概率与实际类别标签频率相匹配时校准良好，而许多模型（包括现代神经网络）开箱即用时并未校准；事后重校准方法分为参数方法（普拉特缩放、贝塔校准）与非参数方法（直方图分箱、等渗校准）两类。<sup>[24](https://arxiv.org/pdf/2505.20761v2.pdf)</sup> 贝塔校准由梅利斯·库尔（Meelis Kull）、特尔莫·M·席尔瓦·菲略（Telmo M. Silva Filho）和彼得·弗拉赫（Peter Flach）于 2017 年在《电子统计学期刊》（Electronic Journal of Statistics）上提出。<sup>[25](https://doi.org/10.1214/17-ejs1338si)</sup> 由于贝叶斯错误率难以计算，已发表工作对其给出界：切尔诺夫界与巴塔查里亚界是经典的上界近似。<sup>[13](https://wiki.eecs.yorku.ca/course_archive/2016-17/F/6327/_media/ml4-decision-rule.pdf)</sup> 已发表的直接对比基准确实存在：例如，伊什法克（Ishfaq）等人（2022，《无线通信与移动计算》）在 UCI 和 Kaggle 数据上比较了朴素贝叶斯与决策树、随机森林、梯度提升决策树和卷积神经网络；后来的综述与研究还将朴素贝叶斯与支持向量机（SVM）、随机森林以及长短期记忆网络（LSTM）等神经分类器进行了比较。

## References

1. [Evaluating State-of-the-Art Classification Models Against Bayes Optimality](https://papers.neurips.cc/paper_files/paper/2021/file/4e0ccd2b894f717df5ebc12f4282ee70-Paper.pdf)
2. [Chapter 1 sample chapter (Elsevier, Theodoridis & Koutroumbas, Pattern Recognition)](https://booksite.elsevier.com/samplechapters/9780123744869/02~Chapter_1.pdf)
3. [Lecture 5: Bayes Classifier and Naive Bayes (Cornell CS3780, 2025sp)](https://www.cs.cornell.edu/courses/cs3780/2025sp/lectures/lecturenote05.html)
4. [Universal Training of Neural Networks to Achieve Bayes Optimal Classification Accuracy](https://ar5iv.labs.arxiv.org/html/2501.07754)
5. [Demystifying the Optimal Performance of Multi-Class Classification](https://proceedings.neurips.cc/paper_files/paper/2023/file/647e122fc406573c51276692f20379b5-Paper-Conference.pdf)
6. [Bayes Decision Theory (Johns Hopkins, Vision as Bayesian Inference, Lecture 5)](https://www.cs.jhu.edu/~ayuille1/JHUcourses/VisionAsBayesianInference2024/5/Lecture5BayesDecisionTheory.pdf)
7. [Machine Learning (Tom M. Mitchell, 2017 draft chapter): Naive Bayes and Logistic Regression](http://www.cs.cmu.edu/%7Etom/mlbook/NBayesLogReg.pdf)
8. [Zheng, Chenyu and colleagues (2023). Revisiting Discriminative vs. Generative Classifiers: Theory and Implications. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2302.02334)
9. [A Pairwise Naïve Bayes Approach to Bayesian Classification](https://pmc.ncbi.nlm.nih.gov/articles/PMC4832935/)
10. [Pattern Recognition, 2nd Ed. (Duda, Hart & Stork), Bayes classification rule excerpt](https://www.cs.man.ac.uk/~fumie/tmp/bayesclassifier.pdf)
11. [The Bayes Classifier (Georgia Tech ECE 6254 notes, Spring 2024)](https://mdav.ece.gatech.edu/ece-6254-spring2024/notes/03-notes-6254-sp24.pdf)
12. [Bayes Classifier (University of Michigan EECS 598 notes, Clayton Scott)](https://web.eecs.umich.edu/~cscott/past_courses/eecs598w14/notes/02_bayes_classifier.pdf)
13. [Bayesian Decision Theory (York University EECS 6327 lecture slides)](https://wiki.eecs.yorku.ca/course_archive/2016-17/F/6327/_media/ml4-decision-rule.pdf)
14. [6.2 Bayes discriminant rule | Multivariate Statistics](https://rich-d-wilkinson.github.io/MATH3030/6.2-lda-Bayes.html)
15. [Bayesian Classification (Ronny Kohavi, chapter draft; Stanford)](https://ai.stanford.edu/~ronnyk/bayesHB.pdf)
16. [Naive Bayes classifiers (Kevin Murphy, UBC course reading)](https://www.cs.ubc.ca/~murphyk/Teaching/CS340-Fall06/reading/NB.pdf)
17. [Naive Bayes text classification (Stanford IR Book)](https://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html)
18. [1.9. Naive Bayes, scikit-learn documentation](https://scikit-learn.org/stable/modules/naive%5Fbayes.html)
19. [Some History of Optimality (Erich L. Lehmann)](https://www.stat.rice.edu/~tsn4867/all_files/IMS_VOLUME/LEHMANN/Lehmann_hist_opt.pdf)
20. [Abraham Wald (1939). Contributions to the Theory of Statistical Estimation and Testing Hypotheses. The Annals of Mathematical Statistics.](https://doi.org/10.1214/aoms/1177732144)
21. [Abraham Wald (1949). Statistical Decision Functions. The Annals of Mathematical Statistics.](https://doi.org/10.1214/aoms/1177730030)
22. [A History of Inverse Probability from Thomas Bayes to Karl Pearson (A.I. Dale)](https://unina2.on-line.it/sebina/repository/catalogazione/documenti/Dale%20-%20A%20history%20of%20inverse%20probability%20from%20Thomas%20Bayes%20to%20Karl%20Pearson.pdf)
23. [Classification Algorithms (George Nagy, IEEE Trans. Audio and Electroacoustics, 1968)](https://sites.ecse.rpi.edu/~nagy/PDF_chrono/1968_Nagy_Classification_IEEE_Audio_68.pdf)
24. [Practical estimation of the optimal classification error with soft labels and calibration](https://arxiv.org/pdf/2505.20761v2.pdf)
25. [Meelis Kull, Telmo M. Silva Filho, Peter Flach (2017). Beyond sigmoids: How to obtain well-calibrated probabilities from binary classifiers with beta calibration. Electronic Journal of Statistics.](https://doi.org/10.1214/17-ejs1338si)

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

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods › Supervised, unsupervised, and semi-supervised learning › Classification algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/bayes-classifier

English original: https://www.edgepedia.org/bayes-classifier
