The Dual Problem, Support Vectors and Kernels

Lagrange multipliers turn the margin problem into its dual: maximise Σαᵢ − ½ΣΣ αᵢαⱼyᵢyⱼ xᵢ·xⱼ with αᵢ ≥ 0 and Σαᵢyᵢ = 0. The solution is w = Σαᵢyᵢxᵢ, complementary slackness makes αᵢ non-zero only for support vectors, and because the data enters only through dot products, any kernel can replace them.

Machine Learning Techniques

The maximum-margin problem has a hidden second form, its dual, and the dual is where the SVM's best properties come from: it shows that the solution depends only on the support vectors, and that the data enters only through dot products, so kernels apply. Getting there takes one idea from optimisation, Lagrange multipliers for inequality constraints.

Constrained optimisation in brief

Take the general problem

min⁡w  f(w)subject togi(w)≤0,  i=1,…,n.\min_{w}\; f(w) \quad \text{subject to} \quad g_i(w) \le 0,\; i = 1, \dots, n .

Attach a multiplier αi≥0\alpha_i \ge 0 to each constraint and form the Lagrangian

L(w,α)=f(w)+∑iαi gi(w).\mathcal{L}(w, \alpha) = f(w) + \sum_{i} \alpha_i\, g_i(w).

Here is the key observation. For a fixed ww, maximise the Lagrangian over α≥0\alpha \ge 0. If ww breaks some constraint (gi(w)>0g_i(w) > 0), raising αi\alpha_i makes the Lagrangian infinite. If ww satisfies every constraint, every gi(w)≤0g_i(w) \le 0, so the best choice is to make each term zero, and the maximum is just f(w)f(w). So

min⁡w  max⁡α≥0  L(w,α)\min_{w}\; \max_{\alpha \ge 0}\; \mathcal{L}(w, \alpha)

is exactly the original constrained problem: the inner maximum acts as an infinite penalty on infeasible ww.

The dual problem swaps the order:

max⁡α≥0  min⁡w  L(w,α).\max_{\alpha \ge 0}\; \min_{w}\; \mathcal{L}(w, \alpha).

In general the dual's optimum is at most the original (primal) optimum. For convex problems such as the SVM, under a mild condition that holds whenever the data is separable, the two are equal (strong duality), so we may solve whichever form is more convenient.

The SVM dual

For the hard-margin SVM, f(w)=12∥w∥2f(w) = \tfrac12\lVert w\rVert^2 and the constraints are 1−yi(w⊤xi+b)≤01 - y_i(w^\top x_i + b) \le 0. The Lagrangian is

L(w,b,α)=12∥w∥2+∑i=1nαi(1−yi(w⊤xi+b)).\mathcal{L}(w, b, \alpha) = \tfrac12\lVert w\rVert^2 + \sum_{i=1}^{n}\alpha_i\big(1 - y_i(w^\top x_i + b)\big).

Minimise over ww and bb by setting the derivatives to zero:

∂L∂w=w−∑iαiyixi=0  ⟹  w=∑i=1nαiyi xi,∂L∂b=−∑iαiyi=0.\frac{\partial\mathcal{L}}{\partial w} = w - \sum_i \alpha_i y_i x_i = 0 \;\Longrightarrow\; w = \sum_{i=1}^{n}\alpha_i y_i\, x_i , \qquad \frac{\partial\mathcal{L}}{\partial b} = -\sum_i \alpha_i y_i = 0 .

Substitute these back, and ww and bb disappear:

max⁡α∑i=1nαi−12∑i=1n∑j=1nαiαj yiyj xi⊤xjsubject toαi≥0,∑i=1nαiyi=0.\begin{aligned} \max_{\alpha}\quad & \sum_{i=1}^{n}\alpha_i - \frac12\sum_{i=1}^{n}\sum_{j=1}^{n}\alpha_i\alpha_j\, y_i y_j\, x_i^\top x_j \\ \text{subject to}\quad & \alpha_i \ge 0, \qquad \sum_{i=1}^{n}\alpha_i y_i = 0 . \end{aligned}

This is again a convex quadratic program, now in nn variables (one per training point) instead of d+1d + 1.

What the dual reveals

1. The weights are a combination of training points

w=∑iαiyixiw = \sum_i \alpha_i y_i x_i. Once more, the solution lives in the span of the data, just as in kernel PCA and kernel regression.

2. Only support vectors count

At the optimum, the complementary slackness condition holds for every point:

αi (1−yi(w⊤xi+b))=0.\alpha_i\,\big(1 - y_i(w^\top x_i + b)\big) = 0 .

Either αi=0\alpha_i = 0, or the constraint is tight, yi(w⊤xi+b)=1y_i(w^\top x_i + b) = 1, meaning the point lies exactly on the edge of the street. So αi>0\alpha_i > 0 only for support vectors; every other point has αi=0\alpha_i = 0 and drops out of w=∑iαiyixiw = \sum_i \alpha_i y_i x_i. This is the precise form of the statement in the last chapter: the classifier is built from the support vectors alone. The intercept follows from any support vector ss: b=ys−w⊤xsb = y_s - w^\top x_s.

3. The data appears only through dot products

Look at the dual objective: the training points enter only as xi⊤xjx_i^\top x_j. And a prediction for a new point is

f(x)=w⊤x+b=∑i∈SVαiyi xi⊤x+b,f(x) = w^\top x + b = \sum_{i \in \text{SV}}\alpha_i y_i\, x_i^\top x + b ,

again only dot products, and only with the support vectors.

Kernel SVMs

So the kernel trick applies exactly as in Module 3. Replace every dot product by a kernel, xi⊤xj→k(xi,xj)x_i^\top x_j \to k(x_i, x_j):

max⁡α≥0,  ∑αiyi=0  ∑iαi−12∑i,jαiαjyiyj k(xi,xj),f(x)=∑i∈SVαiyi k(xi,x)+b.\max_{\alpha \ge 0,\; \sum\alpha_iy_i = 0}\; \sum_i\alpha_i - \frac12\sum_{i,j}\alpha_i\alpha_j y_iy_j\,k(x_i, x_j), \qquad f(x) = \sum_{i \in \text{SV}}\alpha_i y_i\, k(x_i, x) + b .

This finds the maximum-margin hyperplane in the kernel's feature space without ever computing the feature vectors. With a polynomial kernel the boundary in the original space is a polynomial curve; with the RBF kernel it can wrap around clusters of any shape, such as one ring inside another.

The kernel SVM also solves the cost problem of kernel regression. Kernel regression's prediction needed a kernel value with every training point; the SVM's needs only the support vectors, often a small fraction of the data.

Left: two concentric rings of points; a linear SVM's straight boundary misclassifies many. Right: an RBF-kernel SVM's closed curved boundary around the inner ring, with the support vectors circled near the boundary
A linear SVM cannot separate rings (left); the same algorithm with an RBF kernel draws a closed boundary between them (right). Only the circled support vectors define it.
Try it yourself
Machine Learning Lab: kernel SVM →
Pick the "Rings" data with a linear kernel, then switch to RBF. Raise γ to make each support vector's influence more local and watch the boundary tighten.

Choosing the RBF width

The RBF kernel k(x,x′)=exp⁡(−γ∥x−x′∥2)k(x, x') = \exp(-\gamma\lVert x - x'\rVert^2) (here written with γ=1/2σ2\gamma = 1/2\sigma^2) has a width parameter that matters a great deal. Small γ\gamma (wide kernel): each support vector influences a large region, and the boundary is smooth, approaching a linear one. Large γ\gamma (narrow kernel): influence is very local, the boundary can wrap around individual points, and the model overfits, with almost every point becoming a support vector. γ\gamma and the soft-margin parameter CC (next chapter) are chosen together by cross-validation.

MediumSVMDuality

Using complementary slackness, explain why a point that lies strictly outside the margin has αᵢ = 0.

MediumSVMKernels

Why does the dual formulation, rather than the primal, make kernels possible?

MediumSVMComplexity

A trained RBF SVM has 40 support vectors out of 10,000 training points. What does prediction cost, and what does a much larger count suggest?