M2-039M2: Classical Machine LearningSupport Vector Machines & KernelsMedium
⚡Flashcard Drill➔Mastery:
Compare Linear, Polynomial, and RBF Kernels and Their Decision Boundaries
📐 Mathematical Definition
⚡ One-Sentence Core Answer
Linear kernel is optimal for high-dimensional sparse data (); 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: ; training and inference, fastest execution, ideal when feature count is massive (e.g. Text classification with ).
- •RBF (Gaussian) Kernel: ; universal approximator; hyperparameter dictates locality (large causes tight islands/overfitting).
- •Polynomial Kernel: ; models explicit feature combinations up to degree ; computationally sensitive to numerical scaling.
📐 Mathematical Derivations
Analysis of RBF kernel parameter : In , parameter governs the radius of influence of individual support vectors. (1) As , for all , meaning each support vector forms an isolated Gaussian spike around itself (extreme memorization / high variance). (2) As , , the kernel becomes a flat constant, flattening the decision boundary into a linear plane (high bias). In the polynomial kernel , if inputs are unnormalized with , raising to power triggers floating-point overflow.
🏭 Production Trade-offs
Selection rules of thumb (Hsu et al., 2003): (1) If (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 is moderate () and is small-to-medium, use RBF Kernel with grid search over . (3) If , switch to tree ensembles (LightGBM) or neural networks.
⚠️ Common Interview Pitfalls
- ✕Using RBF kernel when and (adds massive compute overhead with zero accuracy benefit over linear SVM).
- ✕Setting 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.
📚
Associated Knowledge Base Guides & Mindmaps
Explore the comprehensive technical article, exam cards, and global architecture tree.
中文速览与面试要点
比较 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 核不做特征标准化