The hard-margin SVM demands that every training point sit outside the street. One mislabelled point, or two classes that genuinely overlap, makes that impossible, and the optimisation has no solution. Even when separation is possible, insisting on it can force a narrow street that bends around a single unusual point. The soft-margin SVM lets some points break the rule, at a price.
Slack variables
Give each point a slack that measures how far it falls short of the margin, and relax its constraint to
- : the point is on or outside the margin, as before.
- : the point is inside the street but still on the correct side.
- : the point is on the wrong side of the boundary, a training mistake.
Slack is not free. The objective charges for it:
The cost sets the trade-off between a wide street (small ) and few violations (small ).
- Large : violations are expensive, so the SVM tries hard to classify every training point correctly, at the cost of a narrow margin. As it becomes the hard-margin SVM.
- Small : violations are cheap, so the SVM accepts some of them in exchange for a wide, stable margin.
is a regularisation parameter, chosen by cross-validation like in ridge regression (roughly, plays the role of ).
The dual: a box around α
Repeating the Lagrangian derivation with the slack variables (and their non-negativity constraints, which get multipliers ), the condition forces . Everything else is unchanged, so the dual is
The only change from the hard margin is the box constraint : no single point may pull on the solution with more than strength . That is precisely what makes the soft margin robust to outliers. The prediction rule, , and the use of kernels are exactly as before.
Three kinds of points
Complementary slackness now involves both sets of multipliers: and . Working through the cases sorts every training point into one of three groups.
| Where the point is | Role | |
|---|---|---|
| outside the margin, | no influence on the solution | |
| exactly on the margin, , | support vector on the street's edge | |
| inside the margin or misclassified, , | support vector, a "bounded" violator |
Both of the last two groups are support vectors. The points on the edge () are the ones used to compute , since for them exactly. The sparsity of the SVM survives: every point comfortably on its correct side has and could be deleted without changing anything.
The same thing as a loss
Eliminate the slack variables. At the optimum each is as small as the constraints allow:
This is the hinge loss of point : zero when the point is outside the margin on the correct side, growing linearly as it moves into the street and beyond. Substituting, the soft-margin SVM is
(after dividing by ). That is: hinge loss plus an L2 penalty, the same pattern as ridge regression (squared loss plus L2) and regularised logistic regression (log loss plus L2). In this form the SVM can also be trained with (sub)gradient descent, which scales to very large data sets with linear kernels. Module 11 compares the hinge loss with the other classification losses side by side.
Primal or dual?
| Primal | Dual | |
|---|---|---|
| Variables | : | : |
| Kernels | no (needs explicit features) | yes (only dot products) |
| Best when | linear SVM, many points, moderate | non-linear kernels, moderate |
| Typical solver | (sub)gradient descent, coordinate descent | SMO (sequential minimal optimisation) |
The simulator in the Machine Learning Lab trains its SVMs with a simplified version of SMO, which repeatedly picks two multipliers and solves for them exactly while keeping , the standard algorithm behind libraries such as LIBSVM.