5.3 Support Vector Machines
Margins, the dual, and the kernel trick.
These notes walk through the lecture slides. The original deck is unchanged; use (slides) on the course hub if you want that PDF.
The figures follow Deisenroth, Faisal, and Ong, Mathematics for Machine Learning, Theodoridis, and Géron, Hands-On Machine Learning.
1. The main idea
Think of open and filled circles as houses in two villages. A road between them should be as wide as possible and should demolish as few houses as possible. No sensible engineer picks the dash-dotted path in the figure.
A classifier should sit between the dense regions of the two classes, in a sparse belt, leaving the largest possible margin. That is the usual requirement for generalization: small error on points that were not in the training set.

2. Linearly separable classes
If the classes are linearly separable, infinitely many hyperplanes classify the training set with zero error. From that family one can always keep those that satisfy
The SVM picks the one with smallest norm:
is tied directly to the margin.
3. Primal, dual, and support vectors
The constrained problem is the primal. It has a dual. In general the dual only lower-bounds the primal; under convexity (and regularity of the constraints) the values match. SVM meets those conditions, so you may solve either.
The Lagrangian is
KKT stationarity gives
and
Plug that expansion into and solve the dual with a quadratic program:
With a dual solution ,
where is the number of nonzero multipliers. Only points that meet the inequality as an equality, , have . Those points are the support vectors. Recover from any such equality.
4. Notes
- The SVM solution is unique: the cost is strictly convex.
- The dual is usually faster than the primal.
- The dual is what makes the kernel trick possible. In an RKHS the predictor is
5. Non-separable classes
When the classes overlap, allow slack:
A margin error is , i.e. . If that point does not add to the cost. The optimizer tries to drive as many as possible to zero.
The user parameter trades the two terms. Large : a small margin, fewer margin errors. Small : the opposite.
6. Choice of hyper-parameters
is almost always chosen by cross-validation on held-out data.
The other choice is the kernel. Different kernels, different performance. A Gaussian kernel needs enough training points to fill the input space, because matches to the stored point . Training-set size matters.
| Kernel | Formula | Typical use |
|---|---|---|
| Linear | Linearly separable data, or many features relative to | |
| Polynomial | Polynomial-shaped boundaries (e.g. some image tasks) | |
| Gaussian RBF | Complex nonlinear relations | |
| Sigmoid | Periodic or sigmoid-like relations (e.g. some time series) |
7. Practice
-
Where do the support vectors appear in the SVM dual?
-
What does a large do to the margin and to margin errors?
-
Why does the dual make the kernel trick possible?