🧮 Brain Teaser

The SVM That Saw Only Dot Products

You are given a training set {(xi,yi)}i=1N\{(x_i, y_i)\}_{i=1}^N with xi∈Rpx_i \in \mathbb{R}^p and yi∈{−1,+1}y_i \in \{-1, +1\}. The soft-margin SVM solves

min⁡β,β012∥β∥2+C∑i=1Nξisubject to yi(xiTβ+β0)≥1−ξi, ξi≥0.\min_{\beta, \beta_0} \frac{1}{2}\|\beta\|^2 + C\sum_{i=1}^N \xi_i \quad \text{subject to } y_i(x_i^T \beta + \beta_0) \geq 1 - \xi_i,\ \xi_i \geq 0.

After solving the dual, the decision function is

f^(x)=∑i=1Nα^iyi⟨xi,x⟩+β^0.\hat{f}(x) = \sum_{i=1}^N \hat{\alpha}_i y_i \langle x_i, x \rangle + \hat{\beta}_0.

Now suppose instead of raw features xx, you map every point to a very high-dimensional (even infinite-dimensional) feature space via ϕ:Rp→H\phi: \mathbb{R}^p \to \mathcal{H}, and you only have access to k(x,x′)=⟨ϕ(x),ϕ(x′)⟩Hk(x, x') = \langle \phi(x), \phi(x') \rangle_{\mathcal{H}} — you can never compute ϕ(x)\phi(x) explicitly.

The question: Can you still train and deploy the SVM decision function entirely using the kernel kk, without ever computing ϕ(x)\phi(x) explicitly? If yes, write out the dual objective and decision function purely in terms of kk, and explain conceptually why the geometry of the primal problem is fully captured by dot products alone.

SVMkernel trickdual formulationMercer kernelRKHS

Answer: The SVM That Saw Only Dot Products

Key Idea / Intuition

The SVM's geometry — margins, distances, projections — depends on β\beta only through inner products of training points. When you write the dual, β\beta itself disappears and is replaced entirely by pairwise dot products ⟨xi,xj⟩\langle x_i, x_j \rangle. Swapping in k(xi,xj)=⟨ϕ(xi),ϕ(xj)⟩k(x_i, x_j) = \langle \phi(x_i), \phi(x_j) \rangle is therefore a completely seamless substitution: the dual and the decision function never needed ϕ\phi explicitly, only the Gram matrix. This is the kernel trick — you implicitly work in H\mathcal{H} without ever touching it.


Formal Proof / Solution

Step 1: The Dual Objective Depends Only on Dot Products

From the excerpt (ESL eq. 12.13), the Wolfe dual of the soft-margin SVM is

max⁡α LD=∑i=1Nαi−12∑i=1N∑j=1Nαiαjyiyj⟨xi,xj⟩\max_{\alpha}\ L_D = \sum_{i=1}^N \alpha_i - \frac{1}{2}\sum_{i=1}^N\sum_{j=1}^N \alpha_i \alpha_j y_i y_j \langle x_i, x_j \rangle

subject to 0≤αi≤C0 \leq \alpha_i \leq C and ∑iαiyi=0\sum_i \alpha_i y_i = 0.

The primal variable β\beta appears nowhere. Every occurrence of feature vectors is mediated by inner products ⟨xi,xj⟩\langle x_i, x_j \rangle.

Step 2: Kernelized Dual

Replace ⟨xi,xj⟩↦k(xi,xj)\langle x_i, x_j \rangle \mapsto k(x_i, x_j):

max⁡α ∑i=1Nαi−12∑i,jαiαjyiyj k(xi,xj)\max_{\alpha}\ \sum_{i=1}^N \alpha_i - \frac{1}{2}\sum_{i,j} \alpha_i \alpha_j y_i y_j\, k(x_i, x_j)

subject to the same constraints. This is valid as long as kk is a Mercer kernel (i.e., the kernel matrix Kij=k(xi,xj)K_{ij} = k(x_i,x_j) is positive semi-definite), which guarantees the existence of some feature map ϕ\phi with k(x,x′)=⟨ϕ(x),ϕ(x′)⟩Hk(x,x') = \langle \phi(x), \phi(x') \rangle_{\mathcal{H}}.

Step 3: Kernelized Decision Function

The primal solution satisfies β=∑iαiyiϕ(xi)\beta = \sum_i \alpha_i y_i \phi(x_i). The decision function is

f^(x)=⟨ϕ(x),β⟩+β^0=∑i=1Nα^iyi⟨ϕ(xi),ϕ(x)⟩+β^0=∑i=1Nα^iyi k(xi,x)+β^0.\hat{f}(x) = \langle \phi(x), \beta \rangle + \hat{\beta}_0 = \sum_{i=1}^N \hat{\alpha}_i y_i \langle \phi(x_i), \phi(x) \rangle + \hat{\beta}_0 = \sum_{i=1}^N \hat{\alpha}_i y_i\, k(x_i, x) + \hat{\beta}_0.

Again, ϕ\phi vanishes; only k(⋅,⋅)k(\cdot, \cdot) is needed.

Step 4: Why Geometry = Dot Products

All of Euclidean geometry is expressible through inner products:

  • Distance: ∥u−v∥2=⟨u,u⟩−2⟨u,v⟩+⟨v,v⟩\|u - v\|^2 = \langle u,u\rangle - 2\langle u,v\rangle + \langle v,v\rangle
  • Angle / projection: projvu=⟨u,v⟩⟨v,v⟩v\text{proj}_v u = \frac{\langle u,v\rangle}{\langle v,v\rangle} v
  • Margin width: 2∥β∥=2⟨β,β⟩\frac{2}{\|\beta\|} = \frac{2}{\sqrt{\langle \beta, \beta\rangle}}, and ⟨β,β⟩=∑i,jαiαjyiyjk(xi,xj)\langle \beta, \beta\rangle = \sum_{i,j} \alpha_i \alpha_j y_i y_j k(x_i, x_j)

Since the SVM only cares about the geometry (maximizing the margin), and geometry lives entirely in inner products, replacing ⟨⋅,⋅⟩\langle \cdot, \cdot \rangle with k(⋅,⋅)k(\cdot, \cdot) transplants the entire algorithm into H\mathcal{H} — even if H\mathcal{H} is infinite-dimensional — without ever computing a single coordinate of ϕ(x)\phi(x).

The Punchline

The computational cost of training scales with N2N^2 (size of the Gram matrix), not with dim⁡(H)\dim(\mathcal{H}). So an SVM with the RBF kernel k(x,x′)=e−∥x−x′∥2/2σ2k(x,x') = e^{-\|x-x'\|^2/2\sigma^2} implicitly operates in an infinite-dimensional Hilbert space at the same cost as a linear SVM on NN points.

Source: The Elements of Statistical Learning, Hastie, Tibshirani, Friedman (2nd ed.), Chapter 12

Type: ML/StatsSource: The Elements of Statistical Learning, Hastie, Tibshirani, Friedman (2nd ed.), Chapter 12Edit on GitHub ↗