# 铰链损失

铰链损失是一种用于二分类的凸损失函数，对于预测得分 \( h(\mathbf{x}) \) 和标签 \( y \in \{-1, +1\} \)，定义为 \( \ell(h(\mathbf{x}), y) = \max[0,\ 1 - h(\mathbf{x})\,y] \)。当预测符号正确且间隔至少为1时，它不产生任何代价；当间隔低于1时，包括误分类点在内，惩罚会线性增长。它是支持向量机（SVM）所优化的损失。<sup>[1](https://www.cs.cornell.edu/courses/cs4780/2021fa/lectures/lecturenote10.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 对于 \( y \in \{-1, +1\} \)，\( \ell(h(\mathbf{x}), y) = \max[1 - h(\mathbf{x})y, 0] \)；零损失要求符号正确且间隔至少为1<sup>[1](https://www.cs.cornell.edu/courses/cs4780/2021fa/lectures/lecturenote10.html)</sup> |
| 主要用途 | 软间隔SVM的误差函数，结合 \( l_2 \) 正则化项：\( \min_{\mathbf{w},b}\ \mathbf{w}^\top\mathbf{w} + C \sum_{i=1}^{n} \max[1 - y_i(\mathbf{w}^\top\mathbf{x}_i + b), 0] \)<sup>[2](https://www.cs.cornell.edu/courses/cs4780/2018fa/lectures/lecturenote09.html)</sup> |
| 替代性质 | 零一损失的凸上界；累积铰链损失是分类错误次数的上界<sup>[3](https://www.cs.cornell.edu/courses/cs4780/2015fa/web/lecturenotes/lecturenote10.html)</sup><sup> • </sup><sup>[4](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.hinge_loss.html)</sup> |
| 光滑性 | 凸但在铰链点 \( t = 1 \) 处不可微；平方铰链（\( p = 2 \)）变体处处可微<sup>[5](https://course.ccs.neu.edu/ds4420sp20/readings/mml-book.pdf)</sup><sup> • </sup><sup>[6](https://www.cs.cornell.edu/courses/cs4780/2023sp/lectures/pdfs/lecturenote10.pdf)</sup> |
| 次梯度 | 若 \( 1 - y\langle \mathbf{w}, \mathbf{x} \rangle \le 0 \) 则 \( v = 0 \)，否则 \( v = -y\mathbf{x} \)<sup>[7](https://www.cs.huji.ac.il/~shais/UnderstandingMachineLearning/understanding-machine-learning-theory-algorithms.pdf)</sup> |
| 软件默认值 | scikit-learn的`SGDClassifier`默认`loss='hinge'`；`LinearSVC`默认`loss='squared_hinge'`<sup>[8](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html)</sup><sup> • </sup><sup>[9](https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC)</sup> |

## 在支持向量机中的作用

软间隔SVM由科琳娜·科尔特斯（Corinna Cortes）和[弗拉基米尔·瓦普尼克](https://www.edgepedia.org/zh/vladimir-vapnik)（Vladimir Vapnik）于1995年在AT&T贝尔实验室发表的论文《支持向量网络》中提出，通过在优化问题中引入松弛变量，将最优间隔算法推广到不可分数据。<sup>[10](https://doi.org/10.1007/bf00994018)</sup> 当 \( C \neq 0 \) 时，目标函数驱使每个松弛变量 \( \xi_i \) 取其最小可行值，该值具有闭式形式 \( \xi_i = \max(1 - y_i(\mathbf{w}^\top\mathbf{x}_i + b), 0) \)，恰为该点的铰链损失。代入此闭式形式得到无约束形式

\[ \min_{\mathbf{w}, b}\ \mathbf{w}^\top\mathbf{w} + C \sum_{i=1}^{n} \max[1 - y_i(\mathbf{w}^\top\mathbf{x}_i + b), 0], \]

其中 \( l_2 \) 项惩罚分类器复杂度，铰链项惩罚训练误差。参数 \( C \) 平衡两者：非常大的 \( C \) 使SVM严格，推动其正确分类所有点；较小的值则容忍间隔违例，以换取更简单的分离器。<sup>[2](https://www.cs.cornell.edu/courses/cs4780/2018fa/lectures/lecturenote09.html)</sup><sup> • </sup><sup>[11](https://www.cs.cornell.edu/courses/cs4780/2024sp/lectures/pdfs/lecturenote09.pdf)</sup> 用于标准SVM时，铰链项惩罚带符号间隔低于1的样本，而权重范数正则化项控制复杂度并鼓励更大的几何间隔。<sup>[6](https://www.cs.cornell.edu/courses/cs4780/2023sp/lectures/pdfs/lecturenote10.pdf)</sup><sup> • </sup><sup>[24](https://courses.cs.cornell.edu/cs4780/2021fa/lectures/lecturenote10.html)</sup>

由于该形式是光滑加铰链的目标函数，SVM参数可以像逻辑回归那样优化，例如用梯度下降，以铰链损失替代逻辑损失。<sup>[2](https://www.cs.cornell.edu/courses/cs4780/2018fa/lectures/lecturenote09.html)</sup>

## 零一损失的替代函数

分类器最终关心的是零一损失——预测错误时为1，正确时为0——但它不连续，直接优化不切实际。铰链损失是标准的凸替代函数之一：它是零一损失的上界，铰链损失之和是分类错误次数的上界，因此平均铰链损失界定了分类误差，尽管降低铰链损失并不保证训练误差本身降低。<sup>[3](https://www.cs.cornell.edu/courses/cs4780/2015fa/web/lecturenotes/lecturenote10.html)</sup><sup> • </sup><sup>[12](https://proceedings.mlr.press/v37/osadchy15.pdf)</sup> 在常见的基于间隔的损失中，铰链损失和对数损失（用于逻辑回归）是最常被比较的两种零一损失的凸替代函数；当间隔变得非常负时，两条曲线越来越平行。<sup>[3](https://www.cs.cornell.edu/courses/cs4780/2015fa/web/lecturenotes/lecturenote10.html)</sup><sup> • </sup><sup>[13](https://proceedings.mlr.press/v28/nguyen13a.pdf)</sup>

铰链损失与对数损失的区别在于对高置信度的正确预测的处理。一旦间隔达到1，铰链损失恰好为零，因此间隔之外的点对目标函数没有贡献；铰链损失SVM产生的模型仅依赖于间隔上或间隔内的训练点子集，即支持向量。<sup>[14](https://scikit-learn.org/stable/modules/svm.html)</sup> 相比之下，对数损失在每个间隔处都持续惩罚和奖励，从而产生铰链损失无法提供的概率输出。<sup>[3](https://www.cs.cornell.edu/courses/cs4780/2015fa/web/lecturenotes/lecturenote10.html)</sup>

## 优化与次梯度

铰链损失是凸的，但在 \( y\langle \mathbf{w}, \mathbf{x} \rangle = 1 \) 处有一个折点，因此在该单点处不可微。<sup>[5](https://course.ccs.neu.edu/ds4420sp20/readings/mml-book.pdf)</sup> [梯度下降](https://www.edgepedia.org/zh/gradient-descent)通过使用次梯度推广到此类函数，次梯度是满足对所有 \( u \) 有 \( f(u) \ge f(w) + \langle u - w, v \rangle \) 的向量 \( v \)；对于铰链损失 \( f(\mathbf{w}) = \max\{0, 1 - y\langle \mathbf{w}, \mathbf{x} \rangle\} \)，一个有效选择是：当 \( 1 - y\langle \mathbf{w}, \mathbf{x} \rangle \le 0 \) 时 \( v = 0 \)，否则 \( v = -y\mathbf{x} \)。（随机）次梯度下降的收敛分析原样适用，具有与可微凸目标相同的 \( O(1/\sqrt{T}) \) 型速率。<sup>[7](https://www.cs.huji.ac.il/~shais/UnderstandingMachineLearning/understanding-machine-learning-theory-algorithms.pdf)</sup> 实践中，在不可微点处梯度按惯例取为0。<sup>[15](https://www.sciencedirect.com/topics/computer-science/gradient-descent)</sup>

在线性预测器上以铰链损失实例化随机梯度下降，产生间隔感知机算法，且铰链损失是所得分类器在任何样本上的错误率的上界。<sup>[16](https://www.cs.cornell.edu/jeh/bookMay2015.pdf)</sup>

## 变体

**平方铰链。** 将铰链提升到幂 \( p \) 得到族 \( \max[1 - h(\mathbf{x})y, 0]^p \)；\( p = 1 \) 是标准SVM损失，\( p = 2 \) 是平方铰链，该族中每个 \( p > 1 \) 都处处可微。<sup>[6](https://www.cs.cornell.edu/courses/cs4780/2023sp/lectures/pdfs/lecturenote10.pdf)</sup><sup> • </sup><sup>[25](https://www.cs.cornell.edu/courses/cs4780/2022fa/lectures/lecturenote10.html)</sup> scikit-learn的`LinearSVC`默认使用`squared_hinge`并支持`hinge`作为替代，但不支持 \( l_1 \) 惩罚与铰链损失的组合。<sup>[9](https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC)</sup>

**多类铰链损失。** 当时在以色列理工学院的科比·克拉默（Koby Crammer）和约拉姆·辛格（Yoram Singer）在2001年《机器学习研究杂志》的论文中将间隔推广到多类问题，将多类分类转化为单个约束优化问题，而非一组独立的二分类任务；scikit-learn的多类`hinge_loss`度量按克拉默—辛格方法计算间隔。<sup>[17](https://www.jmlr.org/papers/v2/crammer01a.html)</sup><sup> • </sup><sup>[4](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.hinge_loss.html)</sup> 将条件随机场的对数损失与SVM的多类铰链损失相结合的混合损失也已被研究用于多类和结构化预测。<sup>[18](https://arxiv.org/abs/1402.1921)</sup>

**结构化预测。** 铰链损失马尔可夫随机场（HL-MRF）由斯蒂芬·巴赫（Stephen Bach）、伯特·黄（Bert Huang）、本·伦敦（Ben London）和莉丝·吉图尔（Lise Getoor）在2013年UAI会议上提出，是密度由连续变量上的铰链损失构建的图模型，使推理在组合离散预测空间需要近似的情况下仍保持凸性和可扩展性。<sup>[19](https://proceedings.mlr.press/r11/bach13a.html)</sup> Lovász铰链将铰链式损失扩展到由子模集函数评判的结构化二分类。<sup>[20](https://proceedings.mlr.press/v178/nueve22a.html)</sup>

## 性质与局限

铰链损失是无界的：严重误分类的点产生的惩罚随其间隔线性增长，因此经典铰链损失SVM对离群观测敏感。<sup>[21](https://arxiv.org/abs/2207.07690)</sup> 其他凸替代函数也有此特点；非凸的零一损失对离群点稳健，因为它忽略误分类点离边界的距离，代价是直接优化为NP难。<sup>[13](https://proceedings.mlr.press/v28/nguyen13a.pdf)</sup>

赋予铰链损失稀疏性的非光滑性也限制了优化速度。已提出均匀收敛到铰链损失的光滑近似，以利用现代优化算法获得更快的收敛速率；并且已描述了光滑替代函数（如逻辑损失，允许快速优化但一致性速率较慢）与分段线性损失（如铰链，达到最优线性一致性速率但不可微）之间的根本权衡。<sup>[22](https://arxiv.org/abs/2103.00233)</sup><sup> • </sup><sup>[23](https://proceedings.mlr.press/v306/mohri26d.html)</sup>

## References

1. [Cornell CS4780, Lecture 10: Empirical Risk Minimization (2021)](https://www.cs.cornell.edu/courses/cs4780/2021fa/lectures/lecturenote10.html)
2. [Cornell CS4780, Lecture 9: SVM (2018)](https://www.cs.cornell.edu/courses/cs4780/2018fa/lectures/lecturenote09.html)
3. [Cornell CS4780, Lecture 10: Empirical Risk Minimization (2015)](https://www.cs.cornell.edu/courses/cs4780/2015fa/web/lecturenotes/lecturenote10.html)
4. [sklearn.metrics.hinge_loss, scikit-learn documentation](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.hinge_loss.html)
5. [Mathematics for Machine Learning (Deisenroth, Faisal, Ong)](https://course.ccs.neu.edu/ds4420sp20/readings/mml-book.pdf)
6. [Cornell CS4780, Lecture 10 notes, Spring 2023 (PDF)](https://www.cs.cornell.edu/courses/cs4780/2023sp/lectures/pdfs/lecturenote10.pdf)
7. [Shalev-Shwartz & Ben-David, Understanding Machine Learning: From Theory to Algorithms](https://www.cs.huji.ac.il/~shais/UnderstandingMachineLearning/understanding-machine-learning-theory-algorithms.pdf)
8. [SGDClassifier, scikit-learn documentation](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html)
9. [LinearSVC, scikit-learn documentation](https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC)
10. [Cortes, C., Vapnik, V. Support-vector networks. Machine Learning 20, 273–297 (1995)](https://doi.org/10.1007/bf00994018)
11. [Cornell CS4780, Lecture 9: SVM, Spring 2024 (PDF)](https://www.cs.cornell.edu/courses/cs4780/2024sp/lectures/pdfs/lecturenote09.pdf)
12. [Osadchy et al., K-hyperplane Hinge-Minimax Classifier, PMLR v37 (2015)](https://proceedings.mlr.press/v37/osadchy15.pdf)
13. [Nguyen & Sanner, Algorithms for Direct 0–1 Loss Optimization in Binary Classification, ICML 2013](https://proceedings.mlr.press/v28/nguyen13a.pdf)
14. [Support Vector Machines, scikit-learn User Guide](https://scikit-learn.org/stable/modules/svm.html)
15. [Gradient Descent, ScienceDirect Topics overview](https://www.sciencedirect.com/topics/computer-science/gradient-descent)
16. [Kearns & Vazirani-style online learning notes, Cornell (book draft, May 2015)](https://www.cs.cornell.edu/jeh/bookMay2015.pdf)
17. [Crammer, K., Singer, Y. On the Algorithmic Implementation of Multiclass Kernel-based Vector Machines. JMLR 2 (2001), 265–292](https://www.jmlr.org/papers/v2/crammer01a.html)
18. [A Hybrid Loss for Multiclass and Structured Prediction, arXiv:1402.1921](https://arxiv.org/abs/1402.1921)
19. [Bach, Huang, London, Getoor. Hinge-loss Markov Random Fields: Convex Inference for Structured Prediction, UAI 2013](https://proceedings.mlr.press/r11/bach13a.html)
20. [Finocchiaro, Frongillo, Nueve. The Structured Abstain Problem and the Lovász Hinge, COLT 2022](https://proceedings.mlr.press/v178/nueve22a.html)
21. [Support Vector Machines with the Hard-Margin Loss: Optimal Training via Combinatorial Benders' Cuts, arXiv:2207.07690](https://arxiv.org/abs/2207.07690)
22. [Learning with Smooth Hinge Losses, arXiv:2103.00233](https://arxiv.org/abs/2103.00233)
23. [Mohri & Zhong. Linear-Core Surrogates: Smooth Loss Functions with Linear Rates for Classification and Structured Prediction, PMLR v306](https://proceedings.mlr.press/v306/mohri26d.html)
24. [10: Empirical Risk Minimization](https://courses.cs.cornell.edu/cs4780/2021fa/lectures/lecturenote10.html)
25. [10: Empirical Risk Minimization](https://www.cs.cornell.edu/courses/cs4780/2022fa/lectures/lecturenote10.html)

---
*Initially written Sep 17, 2026 · Reviewed: 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 › Supervised learning concepts

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/hinge-loss

English original: https://www.edgepedia.org/hinge-loss
