# 统计分类

**统计分类**（statistical classification）是根据样本的特征，预测该样本属于一组类别中的哪一类的任务。预测结果为某个类别的模型称为分类模型；例如预测输入句子的语言、树的物种，或某种医学状况的阳性或阴性类别的模型。分类与回归形成对照，回归中模型预测的是一个数值而非类别。<sup>[1](https://developers.google.com/machine-learning/glossary?hl=en)</sup><sup> • </sup><sup>[2](https://developers.google.com/machine-learning/crash-course/classification)</sup>

| 关键事实 | 详情 |
|---|---|
| 任务 | 预测样本属于一组类别中的哪一类；二分类预测两个类别之一，多分类预测若干类别之一。<sup>[2](https://developers.google.com/machine-learning/crash-course/classification)</sup> |
| 决策规则 | 在二分类中，由人选择的分类阈值将原始概率分数转换为阳性或阴性类别；阈值并非由模型训练选定。<sup>[1](https://developers.google.com/machine-learning/glossary?hl=en)</sup> |
| 核心指标 | 准确率 = (TP+TN)/(TP+TN+FP+FN)；精确率 = TP/(TP+FP)；召回率（真阳性率）= TP/(TP+FN)；假阳性率 = FP/(FP+TN)。<sup>[3](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall?hl=en)</sup> |
| 阈值权衡 | 提高阈值会减少假阳性并增加假阴性；精确率与召回率往往呈反向关系。<sup>[3](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall?hl=en)</sup> |
| 无阈值评估 | ROC曲线绘制所有阈值下真阳性率对假阳性率的关系；完美模型的AUC为1.0，随机猜测为0.5。<sup>[4](https://developers.google.com/machine-learning/crash-course/classification/roc-and-auc)</sup> |
| 不平衡 | 当一个类别远比另一类别罕见时，准确率通常是糟糕的指标；当阳性仅占数据的1%时，一个100%预测阴性的模型可得到99%的准确率。<sup>[3](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall?hl=en)</sup> |
| 常用方法 | 逻辑回归、k近邻、支持向量机、朴素贝叶斯和决策树等。<sup>[5](https://scikit-learn.org/stable/modules/linear_model.html)</sup><sup> • </sup><sup>[6](https://scikit-learn.org/stable/modules/neighbors.html)</sup><sup> • </sup><sup>[7](https://scikit-learn.org/stable/modules/svm.html)</sup> |

## 二分类决策与混淆矩阵

许多分类器首先产生一个分数，例如0到1之间的概率，然后将该分数转换为类别。在二分类中，分类阈值完成这一转换：原始值大于阈值则预测为阳性类别，即正在检验的类别；较低的值则预测为阴性类别。阈值是人选择的值，而非训练过程中学习到的值，其选择强烈影响假阳性和假阴性的数量。<sup>[1](https://developers.google.com/machine-learning/glossary?hl=en)</sup><sup> • </sup><sup>[8](https://developers.google.com/machine-learning/crash-course/classification/thresholding)</sup>

默认的0.5并不总是合适。当垃圾邮件仅占电子邮件的0.01%，或者错误归档一封合法邮件的代价高于让垃圾邮件进入收件箱时，将所有模型认为至少有50%概率为垃圾邮件的内容标记为垃圾邮件会带来糟糕的结果。阈值为0.9999的垃圾邮件过滤器只有在认为邮件至少有99.99%的概率是垃圾邮件时才将邮件标记为垃圾邮件，这使得误标合法邮件的可能性很低，但也使得它很可能漏掉真正的垃圾邮件。<sup>[8](https://developers.google.com/machine-learning/crash-course/classification/thresholding)</sup>

每个二分类预测有四种结果之一，通常以**混淆矩阵**（confusion matrix）对照真实值——即模型试图预测的观测现实——来排列：

- **真阳性（TP）**：阳性样本被正确分类为阳性，例如垃圾邮件被送入垃圾邮件文件夹。
- **假阳性（FP）**：阴性样本被错误分类为阳性，例如合法邮件被送入垃圾邮件文件夹。
- **假阴性（FN）**：阳性样本被错误分类为阴性，例如垃圾邮件进入了收件箱。
- **真阴性（TN）**：阴性样本被正确分类为阴性。<sup>[8](https://developers.google.com/machine-learning/crash-course/classification/thresholding)</sup>

行合计给出所有预测阳性（TP + FP）和预测阴性（FN + TN）；列合计给出所有实际阳性（TP + FN）和实际阴性（FP + TN）。当实际阳性和实际阴性的总数不接近时，数据集是不平衡的。<sup>[8](https://developers.google.com/machine-learning/crash-course/classification/thresholding)</sup>

## 评估指标

所有标准指标都是在单一固定阈值下计算的，并随阈值变化而变化，因此用户常常调整阈值以优化其中某一指标。<sup>[3](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall?hl=en)</sup>

\[ \text{准确率} = \frac{TP+TN}{TP+TN+FP+FN} \]

准确率是所有分类中正确的比例。在平衡数据集上，它作为粗粒度的质量度量；但在严重不平衡的数据集上，它可能产生误导：当一个类别仅出现约1%时，一个100%预测阴性的模型得到99%的准确率，却毫无用处。Google机器学习速成课程的指导是：仅将准确率与其他指标结合使用，并避免在不平衡数据集上使用它。<sup>[3](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall?hl=en)</sup>

\[ \text{召回率 (TPR)} = \frac{TP}{TP+FN} \qquad \text{FPR} = \frac{FP}{FP+TN} \qquad \text{精确率} = \frac{TP}{TP+FP} \]

召回率，也称真阳性率或检测概率，衡量模型捕获的实际阳性样本的比例；当假阴性的代价高于假阳性时，例如在疾病预测中，它是应优先考虑的指标。假阳性率，或称虚警概率，在假阳性代价更高时更受青睐。精确率衡量阳性预测中实际为阳性的比例，在阳性预测必须准确时使用。F1分数是精确率和召回率的调和平均，

\[ \text{F1} = \frac{2\,TP}{2\,TP + FP + FN}, \]

它平衡了两者，对于类别不平衡的数据集比准确率更可取。<sup>[3](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall?hl=en)</sup>

阈值的选择使这些指标相互制约。提高阈值减少假阳性并增加假阴性，因此精确率趋于上升而召回率下降或保持不变；降低阈值则产生相反的效果。因此精确率和召回率往往呈反向关系，应优先考虑哪个指标取决于具体问题的成本、收益和风险。<sup>[3](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall?hl=en)</sup><sup> • </sup><sup>[9](https://developers.google.com/machine-learning/crash-course/MCE/mc-il-classification-precision-and-recall)</sup>

## ROC曲线与AUC

单阈值指标不能描述模型在所有操作点上的表现。**受试者工作特征（ROC）曲线**——这一名称是二战雷达探测的遗留——通过计算每个可能阈值（实践中为选定间隔）下的真阳性率和假阳性率，并绘制TPR对FPR的关系来画出。完美模型在FPR为0.0时达到TPR为1.0；随机猜测的模型产生从(0,0)到(1,1)的对角线。<sup>[4](https://developers.google.com/machine-learning/crash-course/classification/roc-and-auc)</sup>

**ROC曲线下面积（AUC）**将曲线概括为单个数字，并有直接的解释：它是模型在给定随机选择的一个阳性样本和一个随机选择的阴性样本时，将阳性排在更高位置的概率。完美模型的AUC为1.0；随机猜测为0.5。AUC忽略任何阈值设置并考虑所有可能的阈值，这使得它可用于比较两个模型，只要数据集大致平衡。当数据集不平衡时，精确率-召回率曲线——绘制所有阈值下精确率对召回率的关系——可能提供更好的比较。<sup>[4](https://developers.google.com/machine-learning/crash-course/classification/roc-and-auc)</sup><sup> • </sup><sup>[10](https://developers.google.com/machine-learning/glossary/metrics)</sup>

ROC曲线也指导阈值选择。最接近(0,1)的点代表表现最佳的一系列阈值；如果假阳性代价极高，则选择FPR较低的阈值，即使TPR降低；而如果假阴性代价极高，则优先选择最大化TPR的阈值。<sup>[4](https://developers.google.com/machine-learning/crash-course/classification/roc-and-auc)</sup>

## 分类方法

统计分类由一系列对数据有不同假设的算法来支撑。

**逻辑回归**（logistic regression）使用逻辑函数对每个结果的概率建模。在scikit-learn中，预测概率 \( \hat{p}(X_i) = 1/(1+\exp(-X_i w - w_0)) \) 通过应用阈值（默认为0.5）转换为类别。它是用于分类的线性模型，通过最小化对数损失代价函数来拟合，可选L1、L2或弹性网正则化，并可通过多项逻辑回归扩展到多分类。<sup>[5](https://scikit-learn.org/stable/modules/linear_model.html)</sup>

**k近邻（KNN）**是一种非参数、基于实例的方法：它存储训练数据，并将查询点分配给其k个最近邻中代表最多的类别。较大的k抑制噪声的影响，但使分类边界不够清晰；该方法在决策边界非常不规则的情况下往往很成功。<sup>[6](https://scikit-learn.org/stable/modules/neighbors.html)</sup>

**支持向量机**在高维空间中构造一个超平面或一组超平面来分离类别，选择与任何类别中最近训练点距离最大的超平面。支持向量网络由科琳娜·科尔特斯（Corinna Cortes）和[弗拉基米尔·瓦普尼克](https://www.edgepedia.org/zh/vladimir-vapnik)（Vladimir Vapnik）于1995年9月在*Machine Learning*上提出，作为一种用于二组分类问题的学习机器，将输入向量非线性地映射到高维特征空间，在其中构造线性决策面，并将先前的可分情形扩展到不可分的训练数据。<sup>[11](https://link.springer.com/article/10.1007/BF00994018)</sup><sup> • </sup><sup>[7](https://scikit-learn.org/stable/modules/svm.html)</sup>线性核、多项式核和径向基函数核等核函数允许非线性边界。<sup>[7](https://scikit-learn.org/stable/modules/svm.html)</sup>

**朴素贝叶斯**方法应用[贝叶斯定理](https://www.edgepedia.org/zh/bayes-theorem)，带有“朴素”假设：给定类别时特征条件独立，给出分类规则 \( \hat{y} = \arg\max_y\, P(y) \prod_{i=1}^{n} P(x_i \mid y) \)。<sup>[12](https://scikit-learn.org/stable/modules/naive_bayes.html)</sup>

**决策树**用形如 \( x_j \leq t_m \) 的划分递归地分割特征空间，在每个节点选择使加权不纯度度量（如基尼不纯度或熵（对数损失））最小化的划分。<sup>[13](https://scikit-learn.org/stable/modules/tree.html?highlight=cart)</sup>教科书中对方法的比较还将线性判别分析和二次判别分析归入这一家族，其中QDA作为非参数KNN方法与线性LDA及[逻辑回归](https://www.edgepedia.org/zh/logistic-regression)方法之间的折中。<sup>[14](https://www.statlearning.com/s/ISLR-Seventh-Printing.pdf)</sup>

## 多分类

二分类方法通过分解策略扩展到两个以上的类别。一对多策略为每个类别拟合一个分类器，将该类别与所有其他类别区分；它只需要n_classes个分类器，具有可解释性，因为每个类别对应一个分类器，并且是最常用的多分类策略，也是scikit-learn中合理的默认选择。一对一策略则为每一对类别训练一个分类器；SVC在内部使用这种方案，构造 \( n_{\text{classes}} \cdot (n_{\text{classes}} - 1)/2 \) 个分类器。<sup>[15](https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html)</sup><sup> • </sup><sup>[7](https://scikit-learn.org/stable/modules/svm.html)</sup>逻辑回归也可以直接作为所有K个类别上的多项逻辑回归来拟合。<sup>[5](https://scikit-learn.org/stable/modules/linear_model.html)</sup>

## 类别不平衡

在现实世界的数据中，不平衡数据集——其中一个类别远比另一个类别常见——比平衡数据集更常见：欺诈性购买可能占信用卡交易的不到0.1%，感染罕见病毒的患者在医学数据集中不到0.01%。标准训练混淆了两个目标：学习每个类别的样子和学习每个类别有多常见，而不平衡使第二个目标占主导。先对多数类降采样再对其加权提升的两步技术将这两个目标分开，在减少预测偏差的同时平衡类别代表性。<sup>[16](https://developers.google.com/machine-learning/crash-course/overfitting/imbalanced-datasets)</sup>

## References

1. [Machine Learning Glossary, Google for Developers](https://developers.google.com/machine-learning/glossary?hl=en)
2. [Classification, Machine Learning Crash Course, Google for Developers](https://developers.google.com/machine-learning/crash-course/classification)
3. [Classification: Accuracy, recall, precision, and related metrics, Google for Developers](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall?hl=en)
4. [Classification: ROC and AUC, Google for Developers](https://developers.google.com/machine-learning/crash-course/classification/roc-and-auc)
5. [Linear Models, scikit-learn documentation](https://scikit-learn.org/stable/modules/linear_model.html)
6. [Nearest Neighbors, scikit-learn documentation](https://scikit-learn.org/stable/modules/neighbors.html)
7. [Support Vector Machines, scikit-learn documentation](https://scikit-learn.org/stable/modules/svm.html)
8. [Thresholds and the confusion matrix, Google for Developers](https://developers.google.com/machine-learning/crash-course/classification/thresholding)
9. [Classification: precision and recall interactive, Google for Developers](https://developers.google.com/machine-learning/crash-course/MCE/mc-il-classification-precision-and-recall)
10. [Machine Learning Glossary: Metrics, Google for Developers](https://developers.google.com/machine-learning/glossary/metrics)
11. [Cortes, C. and Vapnik, V. (1995). Support-vector networks. Machine Learning 20, 273–297.](https://link.springer.com/article/10.1007/BF00994018)
12. [Naive Bayes, scikit-learn documentation](https://scikit-learn.org/stable/modules/naive_bayes.html)
13. [Decision Trees, scikit-learn documentation](https://scikit-learn.org/stable/modules/tree.html?highlight=cart)
14. [James, G. et al. An Introduction to Statistical Learning, Springer Texts in Statistics](https://www.statlearning.com/s/ISLR-Seventh-Printing.pdf)
15. [OneVsRestClassifier, scikit-learn documentation](https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html)
16. [Datasets: Class-imbalanced datasets, Google for Developers](https://developers.google.com/machine-learning/crash-course/overfitting/imbalanced-datasets)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 19, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: 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/statistical-classification

English original: https://www.edgepedia.org/statistical-classification
