# 单类支持向量机

单类支持向量机（One-Class SVM，OCSVM）是一种无监督机器学习算法，它从无标签数据中估计概率分布的支撑集（即分布概率非零的区域），返回一个决策函数：在包含训练数据的区域上为正，在区域外为负。该算法由 [伯恩哈德·舍尔科普夫](https://www.edgepedia.org/zh/bernhard-scholkopf)（Bernhard Schölkopf）、约翰·C·普拉特（John C. Platt）、约翰·肖-泰勒（John Shawe-Taylor）、亚历克斯·J·斯莫拉（Alex J. Smola）和罗伯特·C·威廉姆森（Robert C. Williamson） 在《神经计算》（*Neural Computation*）13（2001），第 1443–1471 页提出，是支持向量算法向无标签数据情形的自然推广。<sup>[1](https://research.google/pubs/estimating-the-support-of-a-high-dimensional-distribution/)</sup>

| 关键事实 | 详情 |
|---|---|
| 原始文献 | 舍尔科普夫、普拉特、肖-泰勒、斯莫拉和威廉姆森，《神经计算》13（2001），第 1443–1471 页<sup>[1](https://research.google/pubs/estimating-the-support-of-a-high-dimensional-distribution/)</sup> |
| 所解决的问题 | 估计输入空间的一个子集 S，使得从潜在分布 P 中抽取的测试点落在 S 之外的概率等于预先指定的、介于 0 与 1 之间的值<sup>[1](https://research.google/pubs/estimating-the-support-of-a-high-dimensional-distribution/)</sup> |
| 解的形式 | 在训练数据的一个可能很小的子集上的核展开，通过控制关联特征空间中权重向量的长度进行正则化；系数由二次规划求得<sup>[1](https://research.google/pubs/estimating-the-support-of-a-high-dimensional-distribution/)</sup> |
| 关键参数 | \( \nu \)，训练误差比例的上界和支持向量比例的下界，取值区间为 (0, 1]；scikit-learn 中默认为 0.5<sup>[2](https://sklearn.org/stable/modules/generated/sklearn.svm.OneClassSVM.html)</sup> |
| 默认核 | 径向基函数（RBF），也是通常的选择；其带宽参数没有精确的设定公式<sup>[3](https://scikit-learn.org/stable/modules/outlier_detection)</sup> |
| 已知弱点 | 对离群点敏感，因此在受污染数据上的离群点检测表现不佳；更适合在干净训练数据上做新颖性检测<sup>[3](https://scikit-learn.org/stable/modules/outlier_detection)</sup> |
| 可扩展性 | 核化算法即使在最优情况下，复杂度也随样本数呈二次增长；线性在线变体 SGDOneClassSVM 为线性复杂度<sup>[3](https://scikit-learn.org/stable/modules/outlier_detection)</sup> |

## 所解决的问题

考虑由潜在概率分布 P 生成的数据；任务是找到输入空间的一个简单区域 S，使得从 P 中随机抽取的测试点落在 S 之外的概率与 0 到 1 之间预先选定的值相符。2001 年的论文通过估计一个在 S 上为正、在 S 的补集上为负的函数 f 来处理这一问题。<sup>[1](https://research.google/pubs/estimating-the-support-of-a-high-dimensional-distribution/)</sup> 在实际意义上，该算法从单一类别的样本中学习“正常性”的模型，从而将远离训练数据的新点标记为新颖或异常。<sup>[4](https://pta.edu.pl/proc/v7p227)</sup>

在几何上，其思想是为对应于所选核的特征空间定义一个边界，用最大间隔将变换后的训练数据与该特征空间的原点分开。<sup>[5](https://www.robots.ox.ac.uk/~davidc/pubs/NDreview2014.pdf)</sup> 由于到特征空间的变换是隐式的，该方法能够拟合正常数据与新颖数据之间的复杂非线性边界，这是它在新颖性检测中广受欢迎的主要原因之一。<sup>[6](https://arxiv.org/abs/2104.11146)</sup>

## 形式化与求解

决策函数采取核展开的形式，展开基于训练数据的一个可能很小的子集。正则化通过控制关联特征空间中权重向量的长度来实现，展开系数通过求解一个二次规划问题得到，原作者通过对输入模式对进行序列优化来求解。论文还对该算法的统计性能作了理论分析。<sup>[1](https://research.google/pubs/estimating-the-support-of-a-high-dimensional-distribution/)</sup>

在标准形式中，二次规划最小化 \( \frac{1}{2}\|\mathbf{w}\|^2 + \frac{1}{\nu N}\sum_{i=1}^{N}\xi_i - \rho \)，约束条件为 \( \langle \mathbf{w} \cdot \boldsymbol{\phi}(\mathbf{z}_i)\rangle \ge \rho - \xi_i \) 且 \( \xi_i \ge 0 \) 对所有训练点成立，其中 \( \boldsymbol{\phi} \) 将输入映射到更高维的特征空间。估计的支撑集是满足 \( \langle \mathbf{w}^* \cdot \boldsymbol{\phi}(\mathbf{z})\rangle \ge \rho^* \) 的点集。<sup>[7](https://link.springer.com/article/10.1007/s12351-023-00788-4)</sup> 超参数 \( \nu \) 决定目标函数各分量所占的权重。<sup>[7](https://link.springer.com/article/10.1007/s12351-023-00788-4)</sup>

## 参数与软件

scikit-learn 的实现 `svm.OneClassSVM` 基于 libsvm，接受线性、多项式、RBF、S 形函数和预计算核，默认为 RBF。核系数 `gamma` 默认为 `scale`，即 \( 1/(n_{\text{features}} \cdot \mathrm{X.var()}) \)；该默认值在 0.22 版本中取代了 `auto`（\( 1/n_{\text{features}} \)）。`nu` 参数被称为单类 SVM 的间隔，它给出一个新的正常观测落在模型所学边界之外的可能性。<sup>[2](https://sklearn.org/stable/modules/generated/sklearn.svm.OneClassSVM.html)</sup><sup> • </sup><sup>[3](https://scikit-learn.org/stable/modules/outlier_detection)</sup>

通常选择 RBF 核，尽管其带宽参数没有精确的公式或算法来设定。对于大型数据集，`linear_model.SGDOneClassSVM` 提供了一种在线线性实现，其复杂度随样本数线性增长；结合核近似技术，它可以逼近核化版本的解，而核化版本即使在最优情况下，复杂度也随样本数呈二次增长。<sup>[3](https://scikit-learn.org/stable/modules/outlier_detection)</sup>

## 新颖性检测与离群点检测

该方法是为新颖性检测设计的：在一个分布的一组干净样本上训练，并判断新观测是否来自同一总体。离群点检测是另一种情形，其中训练数据已被离群点污染，没有可用的干净正常观测集。已知单类 SVM 对离群点敏感，因此在离群点检测中表现不佳；它仍可用于该情形，但需要精细调整 `nu` 以处理离群点并防止过拟合。<sup>[3](https://scikit-learn.org/stable/modules/outlier_detection)</sup>

一个密切相关的单类方法是 大卫·M·J·塔克斯（David M. J. Tax）和罗伯特·P·W·杜因（Robert P. W. Duin）提出的[支持向量数据描述](https://www.edgepedia.org/zh/support-vector-data-description)（SVDD），发表于《机器学习》（*Machine Learning*）54（2004），第 45–66 页。受支持向量分类器启发，SVDD 围绕数据集获得一个球形边界，通过核函数使其具有灵活性，并对训练集中的离群点具有鲁棒性。<sup>[8](https://www.researchgate.net/publication/226109293_Support_Vector_Data_Description)</sup>

## 应用

文献记载的应用横跨若干领域：

- **天文学。** 应用于覆盖全天的中红外 AllWISE 星表，算法在具有 SDSS DR13 光谱证认的天体上训练，OCSVM 标记了约 40,000 个具有异常测光模式的源，这些源与受遮蔽和未受遮蔽的活动星系核候选体相关，包括其他基于 WISE 的活动星系核星表中没有的严重红化的活动星系核/类星体候选体。<sup>[4](https://pta.edu.pl/proc/v7p227)</sup>
- **机器人学。** 单类 SVM 和自编码器模型仅利用电机电流测量和机器人动力学模型来检测机器人操作臂的碰撞，无需额外的外部传感器或手动阈值调整；在六关节操作臂上的实验表明，仅使用无碰撞训练数据即可稳健地检测硬碰撞和软碰撞。<sup>[9](https://snu.elsevierpure.com/en/publications/collision-detection-for-robot-manipulators-using-unsupervised-ano/)</sup>
- **网联车辆。** 在网联和自动驾驶车辆交通中，预先训练好的 OCSVM 模型用于检测传感器异常，并结合基于跟车运动模型的自适应扩展[卡尔曼滤波](https://www.edgepedia.org/zh/kalman-filter)器。<sup>[10](https://arxiv.org/abs/1911.01531)</sup>
- **航天器遥测。** OCSVM 广泛用于航天器系统的健康监测，因其泛化能力强、鲁棒性好、训练和测试速度快，且在使用相对少量样本时仍具有高准确率而受到重视。<sup>[11](https://www.sciencedirect.com/science/article/pii/S0951832023006312)</sup>
- **生产经济学。** 该算法已被改造用于估计生产技术，将技术视为投入与产出联合概率分布的支撑集，并与数据包络分析进行了比较。<sup>[7](https://link.springer.com/article/10.1007/s12351-023-00788-4)</sup>

## 与其他异常检测器的比较

基准研究经常将单类 SVM 与孤立森林（Isolation Forest）、局部离群因子（Local Outlier Factor）及相关方法进行比较，结果取决于数据和设置。在一个合成数据集上，单类 SVM、孤立森林和稳健协方差在识别离群点方面更为有效，孤立森林在平衡精确率与召回率方面略优于其他方法。<sup>[12](https://www.sciencedirect.com/science/article/pii/S2468227624003284)</sup> 在 TON_IoT 恒温器数据集上，孤立森林在准确率、精确率、召回率和 F1 分数上始终优于 OC-SVM，并且在推理时间、模型大小和峰值内存占用方面的计算开销明显更小，因而更适合资源受限的物联网边缘设备。<sup>[13](https://ieeexplore.ieee.org/abstract/document/11381608)</sup> 一篇关于基于隔离的检测的综述同样报告，孤立森林在 AUC 和处理时间上优于单类 SVM。<sup>[14](https://bishtref.com/articles/10.1145/2133360.2133363)</sup>

实际的权衡源于算法的结构。传统的 OCSVM 会带来显著的内存需求，并且随着训练集增大，预测时的计算代价高昂，因为空间和时间随训练点数量增长；这促使研究者将 Nyström 近似和草图近似与聚类及高斯混合模型相结合，以在不牺牲检测准确率的前提下加速预测。<sup>[6](https://arxiv.org/abs/2104.11146)</sup> 2024 年的一篇单类分类综述还提醒，单类图像基准上许多排名靠前的算法并非真正的单类方法，因为它们使用了离群点暴露或预训练的多类模型，并主张不应将二分类和多分类分类器与单类方法直接比较。<sup>[15](https://arxiv.org/abs/2404.17931)</sup>

## References

1. [Schölkopf, B., Platt, J. C., Shawe-Taylor, J., Smola, A. J., Williamson, R. C. (2001). Estimating the Support of a High-Dimensional Distribution. Neural Computation 13, 1443–1471.](https://research.google/pubs/estimating-the-support-of-a-high-dimensional-distribution/)
2. [sklearn.svm.OneClassSVM, scikit-learn documentation](https://sklearn.org/stable/modules/generated/sklearn.svm.OneClassSVM.html)
3. [Novelty and Outlier Detection, scikit-learn User Guide](https://scikit-learn.org/stable/modules/outlier_detection)
4. [Solarz, A., Bilicki, M., Pollo, A. (2018). Search for unusual objects in the WISE Survey. Proceedings of the Polish Astronomical Society, vol. 7, 227–232.](https://pta.edu.pl/proc/v7p227)
5. [Pimentel, M. A. F. et al. (2014). A review of novelty detection. Signal Processing.](https://www.robots.ox.ac.uk/~davidc/pubs/NDreview2014.pdf)
6. [An Efficient One-Class SVM for Anomaly Detection in the Internet of Things. arXiv:2104.11146.](https://arxiv.org/abs/2104.11146)
7. [Measuring technical efficiency through OneClass Support Vector Machines. Operational Research (2023).](https://link.springer.com/article/10.1007/s12351-023-00788-4)
8. [Tax, D. M. J., Duin, R. P. W. (2004). Support Vector Data Description. Machine Learning 54, 45–66.](https://www.researchgate.net/publication/226109293_Support_Vector_Data_Description)
9. [Park, K. M. et al. (2022). Collision Detection for Robot Manipulators Using Unsupervised Anomaly Detection Algorithms. IEEE/ASME Transactions on Mechatronics 27(5), 2841–2851.](https://snu.elsevierpure.com/en/publications/collision-detection-for-robot-manipulators-using-unsupervised-ano/)
10. [Wang, Y., Masoud, N., Khojandi, A. Real-Time Sensor Anomaly Detection and Recovery in Connected Automated Vehicle Sensors. arXiv:1911.01531.](https://arxiv.org/abs/1911.01531)
11. [Anomaly detection in telemetry data using a jointly optimal one-class support vector machine with dictionary learning. Reliability Engineering & System Safety.](https://www.sciencedirect.com/science/article/pii/S0951832023006312)
12. [Anomaly detection using unsupervised machine learning algorithms: A simulation study. Scientific African 26 (2024).](https://www.sciencedirect.com/science/article/pii/S2468227624003284)
13. [Unsupervised Anomaly Detection for Smart IoT Devices: Performance and Resource Comparison. IEEE COMPAS 2025.](https://ieeexplore.ieee.org/abstract/document/11381608)
14. [Liu, F. T., Ting, K. M., Zhou, Z.-H. (2012). Isolation-Based Anomaly Detection. ACM TKDD 6(3).](https://bishtref.com/articles/10.1145/2133360.2133363)
15. [Hayashi, T. et al. (2024). Critical Review for One-class Classification: recent advances and the reality behind them. arXiv:2404.17931.](https://arxiv.org/abs/2404.17931)

---
*Initially written Oct 15, 2026*

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/one-class-support-vector-machine

English original: https://www.edgepedia.org/one-class-support-vector-machine
