# 核技巧

核技巧是机器学习中的一种计算技术：它改写那些只依赖于特征向量之间内积的算法，使每个内积 \(\langle \phi(x), \phi(x') \rangle\) 都被一个直接作用于原始输入的核函数 \(k(x, x')\) 求值所替代，从而让算法能够在一个高维或无限维的特征空间中运行，而无需显式计算特征映射 \(\phi\)。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup><sup> • </sup><sup>[2](https://www.cs.cornell.edu/courses/cs6241/2025sp/lec/2025-03-04.html)</sup>

| 关键事实 | 细节 |
|---|---|
| 作用 | 将对偶形式算法中的每个内积 \(\langle \phi(x), \phi(x') \rangle\) 替换为核求值 \(k(x, x')\)，因此从不构造特征映射。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup> |
| 算例 | 对于 \(\phi(x) = (x_1^2, \sqrt{2}\,x_1 x_2, x_2^2)\)，\(\mathbb{R}^3\) 中的内积等于 \((x^\top x')^2\)，即二次齐次多项式核。<sup>[3](https://mlweb.loria.fr/book/en/kerneltrick.html)</sup> |
| 成本节省 | 在 \(\mathbb{R}^p\) 中包含所有二次特征时，显式预测中每次内积计算的成本为 \(O(p^2)\)；而核 \((x^\top x')^2\) 的成本为 \(O(p)\)。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup> |
| 有效性条件 | 函数 \(k\) 是内积核，当且仅当它是半正定核（阿龙扎因定理，Aronszajn's theorem）。<sup>[4](https://bloch.ece.gatech.edu/ece6254su20/ece6254su20-lecture7-1.html)</sup> |
| 标准核 | 齐次多项式 \((u^\top v)^m\)、\(c>0\) 的非齐次多项式 \((u^\top v + c)^m\)，以及径向基函数核 \(\exp(-\|u - v\|^2 / 2\sigma^2)\).<sup>[4](https://bloch.ece.gatech.edu/ece6254su20/ece6254su20-lecture7-1.html)</sup> |
| 代表性应用 | 支持向量机是与推广核技巧最相关的方法。<sup>[3](https://mlweb.loria.fr/book/en/kerneltrick.html)</sup> |
| 主要局限 | 核方法难以扩展到大规模数据集，这促成了随机傅里叶特征和尼斯特伦方法等近似方法的发展。 |

## 动机：无需付出高成本的非线性特征

许多基本分类器，包括线性判别分析、逻辑回归和感知机，都会产生线性决策边界。对于线性不可分的数据，可以通过一个非线性特征映射 \(\Phi : \mathbb{R}^d \to \mathbb{R}^p\) 映射每个输入，并对变换后的向量 \(\Phi(x)\) 应用线性方法，使其变得可分。<sup>[4](https://bloch.ece.gatech.edu/ece6254su20/ece6254su20-lecture7-1.html)</sup> 困难在于，要达到良好的近似，可能需要非常高维的 \(\phi(x)\)，这会提高计算成本；而对某些问题来说，直接设计好的特征本身也很困难。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup>

这一技巧背后的观察是，许多学习算法写成对偶形式后，只通过内积接触特征。在支持向量机使用的最大间隔优化中，最优权重向量具有形式 \(w = \sum_{i=1}^N \alpha_i \Phi(x_i)\)，因此目标函数与预测都归结为若干项 \(\langle \Phi(x_i), \Phi(x_j) \rangle\) 和 \(\langle \Phi(x_i), \Phi(x) \rangle\) 之和。第一种量只有 \(N^2\) 个，\(\Phi(x)\) 的维数从未显式出现，非线性特征也完全不必计算。<sup>[4](https://bloch.ece.gatech.edu/ece6254su20/ece6254su20-lecture7-1.html)</sup> 同样的结构也出现在平方损失上的随机梯度下降中：经过 \(t\) 次更新后，权重向量是一个组合 \(\beta_t = \sum_i \alpha_i \phi(x_i)\)，而预测则是内积 \(\langle \phi(x_i), \phi(x) \rangle\) 的组合。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup>

**二次示例。** 对于 \(\mathbb{R}^2\) 中的输入，映射 \(\phi(x) = (x_1^2, \sqrt{2}\,x_1 x_2, x_2^2)\) 到 \(\mathbb{R}^3\) 给出

\[ \langle \phi(x), \phi(x') \rangle = x_1^2 {x_1'}^2 + 2 x_1 x_2 x_1' x_2' + x_2^2 {x_2'}^2 = (x^\top x')^2. \]

右端是二次齐次多项式核，无需构造 \(\phi\) 即可计算。<sup>[3](https://mlweb.loria.fr/book/en/kerneltrick.html)</sup> 在 \(\mathbb{R}^p\) 中，完整的二次特征映射具有 \(O(p^2)\) 维。显式计算 \(\beta\) 并用 \(\langle \beta, \phi(x) \rangle\) 进行预测需要 \(O(p^2)\) 时间，而计算 \(\langle \phi(x), \phi(x') \rangle = (x^\top x')^2\) 只需 \(O(p)\) 时间；随后利用 \(N\) 个训练点对一个新点进行预测的代价为 \(O(Np)\)。在数学上，算法并未改变；核技巧纯粹是一种计算捷径。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup>

## 什么算作核

函数 \(k : \mathcal{X} \times \mathcal{X} \to \mathbb{R}\) 是一个半正定（PSD）核，如果对于每个有限点集 \(x_1, \dots, x_n \in \mathcal{X}\)，以 \(K_{ij} = k(x_i, x_j)\) 为元素的核矩阵 \(K\) 都是半正定的；等价地说，\(k\) 是对称的，且对所有系数向量 \(\alpha\) 都有 \(\alpha^\top K \alpha \geq 0\)。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup><sup> • </sup><sup>[4](https://bloch.ece.gatech.edu/ece6254su20/ece6254su20-lecture7-1.html)</sup> 阿龙扎因定理从两个方向闭合了这一循环：一个函数是内积核，即存在一个希尔伯特空间 \(\mathcal{H}\) 和一个映射 \(\Phi\)，使得 \(k(u, v) = \langle \Phi(u), \Phi(v) \rangle_{\mathcal{H}}\)，当且仅当 \(k\) 是半正定的。<sup>[4](https://bloch.ece.gatech.edu/ece6254su20/ece6254su20-lecture7-1.html)</sup> [默塞尔定理](https://www.edgepedia.org/zh/mercers-theorem)（Mercer's theorem）为紧域上的核给出了一个相关判据，提供特征展开，从而揭示相关特征空间与再生核[希尔伯特空间](https://www.edgepedia.org/zh/hilbert-space)的结构。<sup>[5](https://github.com/jjceron/rkhs-kernel-methods/blob/main/docs/mercer_theorem.md)</sup>

核可以由更简单的核构建出来。对任意函数 \(f\)，乘积 \(k(x, x') = f(x) f(x')\) 是一个半正定核；核的和是核；核的积也是核，因为两个半正定矩阵的哈达玛积是半正定的；并且这一类在极限下封闭。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup> 从线性核 \(\langle x, x' \rangle\) 出发，这些规则生成多项式核 \((1 + \langle x, x' \rangle)^d\)，其对应的特征空间维数为 \(O(p^d)\)，随次数呈指数增长。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup>

高斯（径向基函数）核 \(k(x, x') = \exp(-\|x - x'\|_2^2 / 2\sigma^2)\) 在课程讲义中被称为机器学习中的首选核，它定义了一个表达能力很强的假设类。它的特征映射是无限维的，因此核是使用它的唯一实际可行方式；参数 \(\sigma^2\) 控制所诱导函数的平滑程度。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup> 并非每一种相似度度量都合格：指示函数 \(k(x, x') = \mathbf{1}[\|x - x'\|_2 \leq 1]\) 不是核。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup>

## 应用与范围

支持向量机是最著名的核方法，其非线性形式通过将最大间隔问题核化而得到。<sup>[3](https://mlweb.loria.fr/book/en/kerneltrick.html)</sup><sup> • </sup><sup>[4](https://bloch.ece.gatech.edu/ece6254su20/ece6254su20-lecture7-1.html)</sup> 由于核只需要是一个半正定相似度函数，核可以定义在非向量数据上。字符串核度量序列相似度，例如通过对公共子序列求和，并在索引位置上施加衰减 \(\lambda^{|\vec{i}| + |\vec{j}|}\)，其应用包括自然语言处理和计算生物学；树核则支持在树结构域上进行支持向量回归，例如计算化学中的定量构效关系问题。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup><sup> • </sup><sup>[6](https://www.sciencedirect.com/science/article/pii/S0925231204005090)</sup>

核还改变了建模视角。实践者不必选择特征映射，而是写下一个被视为相似度的核，从建模角度看这可能更自然；相关的特征映射由阿龙扎因定理保证存在，但仍然是隐式的。<sup>[1](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)</sup>

## 局限及与神经网络的比较

对偶形式是有代价的。核矩阵随训练点数量增长，而可扩展性仍然是核方法的核心挑战；精确核学习的计算成本限制了在固定预算内可达到的函数空间。<sup>[7](https://simons.berkeley.edu/talks/power-limitations-kernel-learning)</sup> [近似](https://www.edgepedia.org/zh/approximation)方法通过用一个显式的低维映射 \(\phi(x) \in \mathbb{R}^D\) 替换核来应对这一问题，使得 \(k(x, x') \approx \phi(x)^\top \phi(x')\)，从而将成本与 \(n\) 解耦。随机傅里叶特征和尼斯特伦方法是标准例子，比较研究发现尼斯特伦方法在精度与训练时间之间取得了很好的权衡。<sup>[8](https://arxiv.org/abs/2004.11154)</sup>

核方法与神经网络之间的关系已在近期的理论和实证工作中得到量化。对于某种初始化尺度，由随机梯度下降训练的宽神经网络可以被再生核希尔伯特空间方法很好地近似，即神经正切核机制。<sup>[9](https://proceedings.nips.cc/paper_files/paper/2020/hash/a9df2255ad642b923d95503b9a7958d8-Abstract.html)</sup> 斯坦福大学（Stanford University）、加州大学伯克利分校（University of California Berkeley）和谷歌研究院（Google Research）的研究人员戈尔巴尼（Ghorbani）、梅（Mei）、米夏凯维奇（Misiakiewicz）和蒙塔纳里（Montanari）在 NeurIPS 2020 的一篇论文中指出，当协变量近乎各向同性时，RKHS 方法会遭遇维数灾难，而神经网络可以通过学习最佳低维表示来克服它；当协变量与目标函数共享低维结构时，这一差距会缩小——他们用一个尖峰协变量模型将这种权衡形式化。<sup>[9](https://proceedings.nips.cc/paper_files/paper/2020/hash/a9df2255ad642b923d95503b9a7958d8-Abstract.html)</sup> 在经验上，核方法在某些图像分类任务上已接近神经网络的性能；一项大规模研究发现，核方法优于全连接有限宽度网络，但不如卷积网络。<sup>[10](https://proceedings.mlr.press/v139/refinetti21b.html)</sup><sup> • </sup><sup>[11](https://research.google/pubs/finite-versus-infinite-neural-networksan-empirical-study/)</sup> 一项基于英国生物样本库（UK Biobank）脑成像数据的研究发现，这种排序会因领域不同而反转：在 MNIST 和 Fashion 上，深度模型优于核模型，核模型优于线性模型；但在结构和功能脑图像上，全连接网络的表现与核模型和线性模型无法区分，而在脑切片上，卷积网络也没有胜过这两者。<sup>[12](https://www.nature.com/articles/s41467-020-18037-z)</sup>

## References

1. [Chapter 14 Kernel Methods, Theory of Machine Learning (Binghamton University)](https://people.math.binghamton.edu/qiao/math605/book/kernel-methods.html)
2. [CS 6241: Numerics for Data Science, Cornell University](https://www.cs.cornell.edu/courses/cs6241/2025sp/lec/2025-03-04.html)
3. [The kernel trick, mlweb.loria.fr book chapter](https://mlweb.loria.fr/book/en/kerneltrick.html)
4. [Introduction to Kernel methods, Matthieu R. Bloch, Georgia Tech ECE 6254](https://bloch.ece.gatech.edu/ece6254su20/ece6254su20-lecture7-1.html)
5. [Mercer's Theorem for Beginners, jjceron/rkhs-kernel-methods, GitHub](https://github.com/jjceron/rkhs-kernel-methods/blob/main/docs/mercer_theorem.md)
6. [A preliminary empirical comparison of recursive neural networks and tree kernel methods, Neurocomputing 64 (2005)](https://www.sciencedirect.com/science/article/pii/S0925231204005090)
7. [The Power and Limitations of Kernel Learning, Simons Institute](https://simons.berkeley.edu/talks/power-limitations-kernel-learning)
8. [Random Features for Kernel Approximation: A Survey on Algorithms, Theory, and Beyond, arXiv:2004.11154](https://arxiv.org/abs/2004.11154)
9. [When Do Neural Networks Outperform Kernel Methods? NeurIPS 2020](https://proceedings.nips.cc/paper_files/paper/2020/hash/a9df2255ad642b923d95503b9a7958d8-Abstract.html)
10. [Classifying high-dimensional Gaussian mixtures: Where kernel methods fail and neural networks succeed, ICML 2021](https://proceedings.mlr.press/v139/refinetti21b.html)
11. [Finite versus Infinite Neural Networks: an Empirical Study, NeurIPS 2020, Google Research](https://research.google/pubs/finite-versus-infinite-neural-networksan-empirical-study/)
12. [Different scaling of linear models and deep learning in UKBiobank brain images versus machine-learning datasets, Nature Communications (2020)](https://www.nature.com/articles/s41467-020-18037-z)

---
*Initially written Oct 15, 2026*

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

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/kernel-trick

English original: https://www.edgepedia.org/kernel-trick
