# 线性分类器

线性分类器通过取特征值加权和的符号来为输入分配类别标签，这一规则构成了[逻辑回归](https://www.edgepedia.org/zh/logistic-regression)、线性支持向量机、感知机以及某些朴素贝叶斯模型（如多项式变体和伯努利变体）的基础，尽管朴素贝叶斯一般而言并非线性。由于预测只需一次点积运算，线性分类器是高维稀疏问题（如文本分类）的标准主力工具，在此类问题上，它们的训练速度至少比核方法快一个数量级，而在大型文档集上的准确率相近。<sup>[1](https://www.csie.ntu.edu.tw/~cjlin/papers/survey-linear.pdf)</sup>

| 关键事实 | |
|---|---|
| 决策规则 | \( \hat{y} = \mathrm{sign}(\mathbf{w} \cdot \phi(\mathbf{x}) + b) \)：得分为正时取+1，否则取−1<sup>[2](https://introml.mit.edu/_static/spring24/LectureNotes/chapter_Classification.pdf)</sup> |
| 几何 | 边界 \( \mathbf{w}^{\mathrm{T}}\mathbf{x} + b = 0 \) 是一个 \( d-1 \) 维超平面；\( \mathbf{w} \) 垂直于该超平面<sup>[2](https://introml.mit.edu/_static/spring24/LectureNotes/chapter_Classification.pdf)</sup> |
| 常用训练损失 | L1合页损失 \( \max(0, 1 - y \cdot \mathbf{w}^{\mathrm{T}}\mathbf{x}) \)、L2合页损失（其平方）以及对数损失 \( \log(1 + e^{-y \cdot \mathbf{w}^{\mathrm{T}}\mathbf{x}}) \)，均为凸且非负<sup>[3](https://www.jmlr.org/papers/volume9/fan08a/fan08a.pdf)</sup> |
| 可扩展性 | 一个包含超过60万个样本的rcv1文本问题可在数秒内完成训练，而通用核SVM求解器需要数小时<sup>[3](https://www.jmlr.org/papers/volume9/fan08a/fan08a.pdf)</sup> |
| 基准规模 | news20：19,996个样本，1,355,191个特征；rcv1：677,399个样本，47,236个特征<sup>[3](https://www.jmlr.org/papers/volume9/fan08a/fan08a.pdf)</sup> |
| 正则化 | L1正则化产生可用于特征选择的稀疏权重向量，测试准确率通常与L2相当<sup>[1](https://www.csie.ntu.edu.tw/~cjlin/papers/survey-linear.pdf)</sup> |
| 难度 | 对于不可分数据，精确最小化0-1损失是NP难的；因此改用凸替代损失<sup>[4](https://mlanthology.org/iclr/2026/he2026iclr-efficient-a/)</sup> |

## 工作原理

\( d \) 维线性分类器由权重向量 \( \mathbf{w} \in \mathbb{R}^d \)（某些文献中写作 \( \boldsymbol{\theta} \)）和标量偏置 \( b \) 定义。它计算得分 \( \mathbf{w} \cdot \phi(\mathbf{x}) + b \)，其中 \( \phi \) 将原始输入映射为特征，当得分为正时预测正类，否则预测负类。<sup>[2](https://introml.mit.edu/_static/spring24/LectureNotes/chapter_Classification.pdf)</sup><sup> • </sup><sup>[5](https://andre-martins.github.io/docs/dsl2020/lecture_02.pdf)</sup>

从几何上看，权重向量定义了一个分离超平面。满足 \( \mathbf{w}^{\mathrm{T}}\phi(\mathbf{x}) + b = 0 \) 的点集是特征空间中的一个超平面，\( \mathbf{w} \) 垂直于该超平面；其在原始输入空间中的原像不一定是超平面。<sup>[2](https://introml.mit.edu/_static/spring24/LectureNotes/chapter_Classification.pdf)</sup> 支持向量机通过选择最大间隔超平面来完善这一图景，即选择使到最近数据点距离最大的超平面；位于间隔边界上的点即为支持向量，间隔公式也适用于线性不可分的数据。<sup>[6](https://www.stat.cmu.edu/~ryantibs/statml/lectures/linearclassification.pdf)</sup> 当类别可分时，通过缩放 \( \mathbf{w} \) 可使得分任意大，因此优化目标是在保持间隔为1的同时最小化 \( \|\mathbf{w}\| \)。<sup>[7](https://courses.grainger.illinois.edu/CS441/fa2025/lectures/Lecture%2007%20-%20Linear%20Classifiers.pdf)</sup>

同一决策规则可支持不同的分类器，区别在于训练中使用的损失函数。合页损失（惩罚误分类间隔的损失；SVM的训练目标）是0-1损失上方最小的凸函数；其最小化器为贝叶斯规则，其拐角特性允许高效计算，但无法从中恢复回归函数 \( m(\mathbf{x}) = E(Y \mid \mathbf{X} = \mathbf{x}) \)。逻辑回归使用不同的凸替代损失。<sup>[6](https://www.stat.cmu.edu/~ryantibs/statml/lectures/linearclassification.pdf)</sup>

## 实现方法

训练最小化样本上凸替代损失之和加上正则化项。LIBLINEAR是一个广泛使用的库，支持L2正则化逻辑回归以及L1损失和L2损失线性SVM，作为带惩罚参数 \( C > 0 \) 的无约束问题求解。<sup>[3](https://www.jmlr.org/papers/volume9/fan08a/fan08a.pdf)</sup> L1-SVM和L2-SVM通过坐标下降训练，而逻辑回归和L2-SVM使用[信赖域](https://www.edgepedia.org/zh/trust-region)牛顿法。<sup>[3](https://www.jmlr.org/papers/volume9/fan08a/fan08a.pdf)</sup> 由于标准逻辑回归和SVM目标是凸的，不存在局部极小值问题，随机梯度下降适用于大型训练集；朴素贝叶斯通常通过从计数中估计类条件概率来拟合，而非通过最小化凸目标。<sup>[5](https://andre-martins.github.io/docs/dsl2020/lecture_02.pdf)</sup> 同一族中的其他替代损失包括指数损失 \( \exp(-y \cdot h) \)；线性SVM和逻辑回归通过将合页损失或对数损失与线性假设及正则化项配对得到，用梯度下降求解。<sup>[8](http://www.datasciencecourse.org/slides/15388_S22_Lecture_12_linear_classification.pdf)</sup>

正则化控制稀疏性和泛化能力。L2正则化惩罚权重平方和；L1正则化惩罚权重绝对值，产生含大量零的稀疏向量，可用于选择特征，且通常给出与L2相当的测试准确率。<sup>[7](https://courses.grainger.illinois.edu/CS441/fa2025/lectures/Lecture%2007%20-%20Linear%20Classifiers.pdf)</sup><sup> • </sup><sup>[1](https://www.csie.ntu.edu.tw/~cjlin/papers/survey-linear.pdf)</sup> 一个常见的推荐工作流程是：将每个样本归一化为单位向量，选择交叉验证准确率最高的 \( C \)，然后获得模型 \( \mathbf{w} \)。<sup>[9](https://www.csie.ntu.edu.tw/~cjlin/papers/kernel-check/kcheck.pdf)</sup>

在完全一般的情形下，对于不可分数据，精确最小化0-1损失已被证明是NP难的，这就是使用替代损失的原因。<sup>[4](https://mlanthology.org/iclr/2026/he2026iclr-efficient-a/)</sup><sup> • </sup><sup>[10](https://www.philchodrow.prof/ml-notes/chapters/20-perceptron.html)</sup>

## 起源

感知机是最早广为人知的线性分类器，由F.罗森布拉特（F. Rosenblatt）在1958年发表于《心理学评论》的论文中提出，被描述为大脑中信息存储和组织的概率模型。<sup>[11](https://doi.org/10.1037/h0042519)</sup> 它还被实现为定制硬件Mark 1感知机，包含400个光电管和由电动机更新的电位器编码权重。<sup>[5](https://andre-martins.github.io/docs/dsl2020/lecture_02.pdf)</sup> 该模型的谱系比感知机更早：早期工作将神经元建模为执行逻辑功能的阈值器件，一个名为Adaline的相关模型用最小均方方法训练。<sup>[12](https://www.mdpi.com/2227-7390/10/24/4730)</sup> Madaline网络将许多Adaline单元组合成多层网络；由于每个Adaline应用符号激活函数，所得网络并非简单的线性网络，可以实现线性不可分的函数。<sup>[23](https://isl.stanford.edu/~widrow/papers/c1988madalinerule.pdf)</sup><sup> • </sup><sup>[13](https://sebastianraschka.com/faq/docs/classifier-history.html)</sup> 当多层感知机用反向传播算法训练后，对分层网络的兴趣重新兴起。<sup>[12](https://www.mdpi.com/2227-7390/10/24/4730)</sup> 在统计学方面，线性分类算法至少可以追溯到线性判别分析。<sup>[4](https://mlanthology.org/iclr/2026/he2026iclr-efficient-a/)</sup> 投票感知机算法由[约阿夫·弗罗因德](https://www.edgepedia.org/zh/yoav-freund)（Yoav Freund）和罗伯特·E.沙皮尔（Robert E. Schapire）于1999年在《机器学习》中提出；它建立在罗森布拉特的感知机算法以及在线学习到批量学习的转换之上，并使用核函数。<sup>[14](https://doi.org/10.1023/a:1007662407062)</sup>

## 变体

这些方法仅在相关模型假设下产生线性决策边界：具有类相关方差的高斯朴素贝叶斯可以产生二次边界，而共享方差给出线性边界，LDA在共享协方差模型下是线性的；各变体在其他方面的区别在于损失、输出或训练过程。

**感知机。** 从分离平面参数的初始猜测开始，算法在每次误分类一个点时更新权重；对于标签 \( y_i \in \{0, 1\} \)，在误分类点上的更新为 \( \mathbf{w}^{(t+1)} = \mathbf{w}^{(t)} + (2y_i - 1) \cdot \mathbf{x}_i \)。<sup>[10](https://www.philchodrow.prof/ml-notes/chapters/20-perceptron.html)</sup> 投票感知机是一种更简单的算法，利用具有大间隔的线性可分数据。<sup>[14](https://doi.org/10.1023/a:1007662407062)</sup>

**逻辑回归。** 它最大化对正确标签的置信度，并提供标签似然的良好估计，而SVM只试图做到足够自信。<sup>[7](https://courses.grainger.illinois.edu/CS441/fa2025/lectures/Lecture%2007%20-%20Linear%20Classifiers.pdf)</sup>

**线性SVM。** 它用合页损失替代0-1损失并最大化间隔。<sup>[6](https://www.stat.cmu.edu/~ryantibs/statml/lectures/linearclassification.pdf)</sup><sup> • </sup><sup>[7](https://courses.grainger.illinois.edu/CS441/fa2025/lectures/Lecture%2007%20-%20Linear%20Classifiers.pdf)</sup>

**线性判别分析。** 该变体通过将数据投影到线性组合 \( U = \mathbf{w}^{\mathrm{T}}\mathbf{X} \) 所定义的直线上，将协变量降为一维。<sup>[6](https://www.stat.cmu.edu/~ryantibs/statml/lectures/linearclassification.pdf)</sup>

**朴素贝叶斯。** 其决策规则——选择得分最大的类别——在对数空间中归结为比较对数几率与0，这是通用线性分类器方程的一个实例；因此在对数空间中，朴素贝叶斯是线性分类器。<sup>[15](https://nlp.stanford.edu/IR-book/html/htmledition/linear-versus-nonlinear-classifiers-1.html)</sup>

## 应用

文本分类是典型应用：实例空间是词出现次数的向量，特征数通常大于50,000，目标如垃圾邮件与正常邮件。<sup>[16](https://www.cs.cornell.edu/courses/cs4780/2013fa/lecture/06-perceptron.pdf)</sup> 在此类数据上，线性分类器与核分类器具有竞争力，因此训练核分类器可能完全是浪费。<sup>[9](https://www.csie.ntu.edu.tw/~cjlin/papers/kernel-check/kcheck.pdf)</sup>

成本优势是结构性的。使用显式权重向量和 \( \phi(\mathbf{x}) = \mathbf{x} \) 时，通过 \( \mathbf{w}^{\mathrm{T}}\mathbf{x} \) 预测一个实例的成本为 \( O(n) \)，而基于核的预测成本可高达 \( O(l \cdot n) \)，其中 \( l \) 是训练样本数，\( n \) 是每个样本的特征数。<sup>[1](https://www.csie.ntu.edu.tw/~cjlin/papers/survey-linear.pdf)</sup> 在线性SVM与RBF核SVM的比较中，线性分类器在训练和测试中至少快一个数量级，且在大型文档集上准确率相近。<sup>[1](https://www.csie.ntu.edu.tw/~cjlin/papers/survey-linear.pdf)</sup> 专用求解器更进一步：一种切割平面算法以可证明的 \( O(s \cdot n) \) 时间训练线性SVM进行分类，其中 \( s \) 是每个样本的非零特征数，在大型数据集上经验上比SVM Light等分解方法快几个数量级。<sup>[17](https://www.cs.cornell.edu/people/tj/publications/joachims_06a.pdf)</sup>

线性分类器还用作冻结深度学习表征上的探针：对于少样本CLIP适配，文献指出了三条参数高效的途径——[线性探测](https://www.edgepedia.org/zh/linear-probing)（在冻结视觉特征上训练线性分类器）、适配器和提示调优。<sup>[18](https://arxiv.org/html/2410.05270v4)</sup> 线性模型仍然是具有竞争力的基线：一篇2023年ACL论文认为，在词袋特征上运行简单线性分类器应伴随文本分类的先进方法，因为先进方法有时才能给出满意结果。<sup>[19](https://aclanthology.org/2023.acl-short.160/)</sup> 线性探测已成为深度学习中核心的分析和适配工具。两阶段方法LP-FT（先线性探测再微调）由富原昭义（Akiyoshi Tomihari）和佐藤一诚（Issei Sato）于2024年在arXiv上分析，在分布内和分布外数据上均优于单独线性探测和微调，因为线性探测获得一个保持预训练特征的近最优线性头；神经正切核分析将NTK矩阵分解为两个分量，并强调线性头范数与初始预测准确率，训练后调整该范数等价于温度缩放，\( f(\mathbf{x})/T = V_{T} \cdot \phi(\mathbf{x}) + b_{T} \)。<sup>[20](https://doi.org/10.48550/arxiv.2405.16747)</sup>

## 局限与替代方案

**非线性。** 线性分类器不能表示一切；经典例子是XOR，没有直线能分离两个类别。<sup>[21](https://www.cs.toronto.edu/~rahulgk/courses/csc311_f22/readings/LinearClassifiers.pdf)</sup> 它能解决线性可分的OR和AND等问题，但不能解决XOR，除非将输入变换为更好的表示。<sup>[5](https://andre-martins.github.io/docs/dsl2020/lecture_02.pdf)</sup> 当没有超平面能分离类别时，例如一个类别呈圆形飞地嵌入另一类别内部，线性分类器会误分类该飞地，而像kNN这样的非线性分类器在训练集足够大时高度准确。<sup>[15](https://nlp.stanford.edu/IR-book/html/htmledition/linear-versus-nonlinear-classifiers-1.html)</sup> 核技巧解决了这个问题：根据Mercer定理，核满足 \( \kappa(\mathbf{x}_i, \mathbf{x}_j) = \phi(\mathbf{x}_i) \cdot \phi(\mathbf{x}_j) \)，因此高维特征空间中的线性分类器在原始空间中是非线性的，代价是对数据集大小的二次依赖。<sup>[5](https://andre-martins.github.io/docs/dsl2020/lecture_02.pdf)</sup> 在核设置中，合页损失变为 \( \max(0, 1 - y_i \cdot (\mathbf{w}^{\mathrm{T}}\phi(\mathbf{x}_i) + b)) \)，对偶问题最小化 \( \tfrac{1}{2}\boldsymbol{\alpha}^{\mathrm{T}}\mathbf{Q}\boldsymbol{\alpha} - \mathbf{e}^{\mathrm{T}}\boldsymbol{\alpha} \)，约束为 \( 0 \leq \alpha_i \leq C \) 且 \( \sum_i \alpha_i y_i = 0 \)，其中 \( Q_{ij} = y_i \cdot y_j K(\mathbf{x}_i, \mathbf{x}_j) \)。<sup>[9](https://www.csie.ntu.edu.tw/~cjlin/papers/kernel-check/kcheck.pdf)</sup>

根据经验法则，如果问题是线性的，更简单的线性分类器最佳；如果问题是非线性的且不能被超平面很好地近似，非线性分类器通常更准确。<sup>[15](https://nlp.stanford.edu/IR-book/html/htmledition/linear-versus-nonlinear-classifiers-1.html)</sup> 在一个具有类别不平衡和标签噪声的合成非线性问题上，已发表的比较显示线性SVM和逻辑回归的测试误差接近7.5%，接近最佳非线性方法，且高于理论模型误差5.19%；根据构造，线性分类器在该数据集上平均而言无法超越噪声水平。<sup>[22](https://eric.univ-lyon2.fr/ricco/tanagra/fichiers/en_Tanagra_Linear_Classifier.pdf)</sup> 线性分类器保留一个优势：显式模型易于解释。<sup>[22](https://eric.univ-lyon2.fr/ricco/tanagra/fichiers/en_Tanagra_Linear_Classifier.pdf)</sup>

**校准。** 合页损失的最小化器是贝叶斯规则，但无法恢复 \( m(\mathbf{x}) = E(Y \mid \mathbf{X} = \mathbf{x}) \)；逻辑回归使用不同的替代损失，确实提供类概率输出。<sup>[6](https://www.stat.cmu.edu/~ryantibs/statml/lectures/linearclassification.pdf)</sup><sup> • </sup><sup>[7](https://courses.grainger.illinois.edu/CS441/fa2025/lectures/Lecture%2007%20-%20Linear%20Classifiers.pdf)</sup>

## References

1. [Recent Advances of Large-scale Linear Classification (survey)](https://www.csie.ntu.edu.tw/~cjlin/papers/survey-linear.pdf)
2. [Classification (MIT Intro to Machine Learning lecture notes)](https://introml.mit.edu/_static/spring24/LectureNotes/chapter_Classification.pdf)
3. [LIBLINEAR: A Library for Large Linear Classification](https://www.jmlr.org/papers/volume9/fan08a/fan08a.pdf)
4. [An Efficient, Provably Optimal Algorithm for the 0-1 Loss Linear Classification Problem](https://mlanthology.org/iclr/2026/he2026iclr-efficient-a/)
5. [Lecture 2: Linear Classifiers (Data Science Lab, U Edinburgh)](https://andre-martins.github.io/docs/dsl2020/lecture_02.pdf)
6. [Linear Classification (CMU 10-701/36-702 lecture notes, Ryan Tibshirani)](https://www.stat.cmu.edu/~ryantibs/statml/lectures/linearclassification.pdf)
7. [Linear Classifiers: Logistic Regression and SVM (UIUC CS441 lecture)](https://courses.grainger.illinois.edu/CS441/fa2025/lectures/Lecture%2007%20-%20Linear%20Classifiers.pdf)
8. [15-388/688 Practical Data Science: Linear classification (CMU)](http://www.datasciencecourse.org/slides/15388_S22_Lecture_12_linear_classification.pdf)
9. [Linear and Kernel Classification: When to Use Which?](https://www.csie.ntu.edu.tw/~cjlin/papers/kernel-check/kcheck.pdf)
10. [Introduction to Classification: The Perceptron](https://www.philchodrow.prof/ml-notes/chapters/20-perceptron.html)
11. [F. Rosenblatt (1958). The perceptron: A probabilistic model for information storage and organization in the brain.. Psychological Review.](https://doi.org/10.1037/h0042519)
12. [Perceptron: Learning, Generalization, Model Selection, Fault Tolerance, and Role in the Deep Learning Era](https://www.mdpi.com/2227-7390/10/24/4730)
13. [How was classification, as a learning machine, developed?](https://sebastianraschka.com/faq/docs/classifier-history.html)
14. [Yoav Freund, Robert E. Schapire (1999). Large Margin Classification Using the Perceptron Algorithm. Machine Learning.](https://doi.org/10.1023/a:1007662407062)
15. [Linear versus nonlinear classifiers (Introduction to Information Retrieval)](https://nlp.stanford.edu/IR-book/html/htmledition/linear-versus-nonlinear-classifiers-1.html)
16. [Learning (Text) Classification Rules, Perceptron (Cornell CS4780)](https://www.cs.cornell.edu/courses/cs4780/2013fa/lecture/06-perceptron.pdf)
17. [Training Linear SVMs in Linear Time](https://www.cs.cornell.edu/people/tj/publications/joachims_06a.pdf)
18. [CLIP's Visual Embedding Projector is a Few-shot Cornucopia (ProLIP)](https://arxiv.org/html/2410.05270v4)
19. [Linear Classifier: An Often-Forgotten Baseline for Text Classification](https://aclanthology.org/2023.acl-short.160/)
20. [Tomihari, Akiyoshi, Sato, Issei (2024). Understanding Linear Probing then Fine-tuning Language Models from NTK Perspective. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2405.16747)
21. [Lecture 3, Part 1: Linear Classification (U Toronto CSC311)](https://www.cs.toronto.edu/~rahulgk/courses/csc311_f22/readings/LinearClassifiers.pdf)
22. [The Linear Classifier on a Nonlinear Problem (Tanagra tutorial)](https://eric.univ-lyon2.fr/ricco/tanagra/fichiers/en_Tanagra_Linear_Classifier.pdf)
23. [C1988madalinerule (isl.stanford.edu)](https://isl.stanford.edu/~widrow/papers/c1988madalinerule.pdf)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 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/linear-classifier

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