M2-039M2: Classical Machine LearningSupport Vector Machines & KernelsMedium
⚡Flashcard Drill➔Mastery:

Compare Linear, Polynomial, and RBF Kernels and Their Decision Boundaries

📐 Mathematical Definition
KRBF=e−γ∥x−x′∥2K_{RBF}=e^{-\gamma\|x-x'\|^2}
⚡ One-Sentence Core Answer
Linear kernel is optimal for high-dimensional sparse data (d≫Nd \gg N); RBF is the universal default for complex non-linear boundaries in moderate dimensions; Polynomial kernel is specialized for structured interactions (e.g. Computer vision/NLP degree-2 crossings).

📌 Key Takeaways

  • •
    Linear Kernel: K(x,z)=xTz+cK(x, z) = x^T z + c; O(d)O(d) training and inference, fastest execution, ideal when feature count is massive (e.g. Text classification with d>50,000d > 50,000).
  • •
    RBF (Gaussian) Kernel: K(x,z)=exp⁡(−γ∥x−z∥2)K(x, z) = \exp(-\gamma \|x - z\|^2); universal approximator; hyperparameter γ\gamma dictates locality (large γ\gamma causes tight islands/overfitting).
  • •
    Polynomial Kernel: K(x,z)=(xTz+c)dK(x, z) = (x^T z + c)^d; models explicit feature combinations up to degree dd; computationally sensitive to numerical scaling.

📐 Mathematical Derivations

Analysis of RBF kernel parameter γ\gamma: In K(x,z)=exp⁡(−γ∥x−z∥2)K(x, z) = \exp(-\gamma \|x - z\|^2), parameter γ=12σ2\gamma = \frac{1}{2\sigma^2} governs the radius of influence of individual support vectors. (1) As γ→∞\gamma \to \infty, K(xi,xj)→0K(x_i, x_j) \to 0 for all xi≠xjx_i \ne x_j, meaning each support vector forms an isolated Gaussian spike around itself (extreme memorization / high variance). (2) As γ→0\gamma \to 0, K(x,z)→1K(x, z) \to 1, the kernel becomes a flat constant, flattening the decision boundary into a linear plane (high bias). In the polynomial kernel K(x,z)=(γxTz+c)dK(x, z) = (\gamma x^T z + c)^d, if inputs are unnormalized with ∥x∥>1\|x\| > 1, raising to power dd triggers floating-point overflow.

🏭 Production Trade-offs

Selection rules of thumb (Hsu et al., 2003): (1) If d≫Nd \gg N (features far exceed samples, e.g. Genomics, text TF-IDF), use Linear Kernel (data is already separable in high-dimensional space without kernel mapping; RBF offers zero gain and risks overfitting). (2) If NN is moderate (N<50,000N < 50,000) and dd is small-to-medium, use RBF Kernel with grid search over (C,γ)(C, \gamma). (3) If N>106N > 10^6, switch to tree ensembles (LightGBM) or neural networks.
⚠️ Common Interview Pitfalls
  • ✕
    Using RBF kernel when d>100,000d > 100,000 and N<10,000N < 10,000 (adds massive compute overhead with zero accuracy benefit over linear SVM).
  • ✕
    Setting γ\gamma too large in RBF SVM without realizing it produces 100% training accuracy with 50% random test accuracy.
🎯 Interviewer Follow-up Inquiries
  • ?
    Why is linear SVM equivalent to a special case of RBF SVM under specific parameter limits?
  • ?
    How does the Sigmoid (Hyperbolic Tangent) kernel connect SVMs to two-layer neural networks?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

Explore the comprehensive technical article, exam cards, and global architecture tree.

← PreviousM2-038: Explain the Kernel Trick, Mercer's Condition, and Implicit High-Dimensional Inner Products📋Back to BankNext →M2-040: Assess the Sensitivity of SVM to Class Imbalance and Label Noise and Industrial Mitigations
中文速览与面试要点

比较 RBF 核、多项式核与线性核的适用场景。

线性核高维稀疏快;RBF 适合中小规模非线性;多项式核可建模特征交互但参数敏感。

核心要点

  • 三种核的特性与适用:① 线性核 K=xᵀx'——等价于线性 SVM,无需调核参数、训练最快(可用 LIBLINEAR 的坐标下降,O(n·p))、模型可解释(有系数);适合 高维稀疏 数据(文本 TF-IDF、one-hot),因为此时数据常已线性可分(维度高 → 更容易线性可分),且 RBF 在高维下距离集中(所有点距离趋同)而失效。② RBF/高斯核 K=exp(−γ‖x−x'‖²)——对应无限维空间,能拟合任意平滑边界;适合 中小规模、低维连续 特征的数据(如 UCI 数据集);需调 γ 与 C,且 必须做特征标准化 (因为核依赖欧氏距离,量纲不同会使距离被大尺度特征主导)。③ 多项式核 K=(xᵀx'+c)^d——显式建模 d 阶特征交互(类似多项式回归),适合已知存在 特征交互 的场景(如物理/化学数据);缺点是 d 与 c 需调、数值不稳定(大数的高次幂溢出)、计算比 RBF 贵。
  • 实践选择指南:① 先试线性核 ——若数据高维稀疏(p>10⁴),线性核通常足够且快;若线性核表现明显差,再试 RBF。② γ 的调优 ——γ 大 → 每个样本影响范围小 → 边界复杂(过拟合);γ 小 → 边界近似线性(欠拟合);常用起点 γ=1/(p·Var(X))(sklearn 的 'scale')。③ 数值稳定性 ——多项式核在高次幂下易溢出,应先用 PolynomialFeatures + 线性核(显式但可控)或改用 RBF。④ 预计算核矩阵 ——若自定义核(如字符串核、图核),可预先计算 n×n 核矩阵传给求解器。⑤ 现代替代 ——对大规模数据,RBF 核可用 随机傅里叶特征 (Random Fourier Features)近似为线性模型,从而用 SGD 训练,把复杂度从 O(n²) 降到 O(n)。
  • 文本高维稀疏常用线性核
  • RBF 需要特征缩放

常见陷阱

  • 对高维稀疏数据用 RBF 核(距离集中导致失效)
  • 对 RBF 核不做特征标准化