Support Vector Machines — Complete Derivation
Hard and soft margin, the Lagrangian, every KKT condition interpreted, both duals derived in full, the kernel trick, and the margin generalisation bound.
Data with and . A hyperplane is , and the classifier is .
The geometric margin
The Euclidean distance from to the hyperplane is
and for a correctly classified point the signed distance is .
Hard margin
We want the hyperplane that maximises the distance to the closest point:
Assume the data is linearly separable. The margin-maximisation problem is equivalent to
which is a strictly convex quadratic program in (convex, not strict, in jointly).
The Lagrangian and the dual
With multipliers for the constraints, the dual problem is
and strong duality holds. The primal solution is recovered as
Key idea
Three things happened in that derivation and all three matter.
- The dual involves the data only through the inner products . Replace them with and the entire derivation goes through verbatim. That is the kernel trick, and it is available because the dual was derived, not as a separate idea.
- The dual has variables and the primal has . For — the kernel case, where may be infinite — the dual is the tractable one.
- The equality constraint is an artefact of the unregularised bias. Formulations without a bias term, or with inside the penalty, have no such constraint. It is worth knowing which convention a piece of software uses.
At the optimum, only for points with — the points lying exactly on the margin. Consequently
and deleting any non-support vector from the training set does not change the solution.
Soft margin
Real data is not separable, so relax the constraints with slacks :
The dual is
— identical to the hard-margin dual except that the multipliers are boxed above by . The slack variables do not appear.
At the optimum, exactly one of the following holds for each :
| Margin | Interpretation | ||
|---|---|---|---|
| interior, correctly classified with room to spare | |||
| on the margin — a margin support vector | |||
| inside the margin or misclassified — a bound support vector |
Key idea
This table is the whole behaviour of the algorithm in one place, and every entry was derived from the KKT conditions rather than asserted. Note that has a clean interpretation: it is the cap on how much influence a single point may have. Small means no point can pull the boundary far — a wide, soft margin tolerant of violations; large approaches the hard-margin problem. It is the inverse of a regularisation strength, as the next proposition makes explicit.
The soft-margin primal is equivalent to the unconstrained convex problem
The kernel SVM
Since the dual depends on the data only through , substitute any positive definite kernel:
with decision function
Positive definiteness of is exactly what makes the dual objective concave (the matrix is PSD, being ), so the dual remains a convex program. Note also that is precisely the form the representer theorem predicts, with the additional information that most coefficients are zero.
The margin generalisation bound
Let and consider the class . Fix . With probability at least , simultaneously for all ,
No dependence on the dimension .
Key idea
Read the bound. It trades empirical margin error against . Maximising the margin at fixed — which is exactly what the SVM primal does — directly minimises the bound's second term. So the algorithm is not a heuristic that happens to have a bound attached; the bound is the justification for the objective.
And the absence of is the point. A linear classifier in infinite dimension (the kernel case) can still generalise, provided the margin is large relative to . This is the precise reason the kernel trick is not automatically a recipe for overfitting.
What this does not say
The bound has real limitations. must be fixed before seeing the data, or a union bound over a grid of values must be paid. and are typically unknown and must be estimated or bounded a priori. And the bound is usually numerically loose: for realistic , , and , the term often exceeds , making the statement vacuous even when the classifier performs well. It explains the shape of the right objective without certifying the performance of a particular trained model — which is the standard situation in learning theory.
Solving the dual
- Observation. The equality constraint means no single can be changed alone; two must move together.
- Select a pair violating the KKT conditions most severely.
- Solve exactly the two-variable subproblem: with held fixed, the objective is a one-dimensional concave quadratic on an interval, so it has a closed-form maximiser followed by clipping to the box .
- Update from the KKT conditions of the changed pair.
- Repeat until the KKT conditions hold to tolerance.
Each step is (to update the cached decision values) and closed-form, which is why SMO made kernel SVMs practical. There is no need for a general QP solver.
Empirical observation — a regularity seen in experiments. No theorem on this page establishes it in general.
SVMs dominated applied machine learning from roughly 1995 to 2012 and are now rare in large-scale settings.
What this does not say
The reasons are computational, not theoretical:
- The kernel matrix is to store and the exact solve is ; SMO reduces the constant but not the asymptotics. At this is impossible.
- Prediction costs kernel evaluations, and the number of support vectors typically grows linearly with on noisy problems, so inference does not amortise.
- Multi-class requires one-versus-rest or one-versus-one reductions rather than a native formulation.
- The kernel must be chosen; learning the representation from data, which is what deep networks do, has proved more effective on perceptual tasks.
What has not aged is the mathematics. The margin theory, the duality derivation and the representer-theorem structure are all still correct and still the cleanest example in the subject of an algorithm derived from a generalisation bound. Linear SVMs, trained by primal methods on the hinge loss, remain competitive and widely used for high-dimensional sparse data.
Problems
The geometric marginProof · Foundation · 15 min Derive the hard-margin SVM dualProof · Graduate · 3 hours Derive the soft-margin SVM dualProof · Graduate · 3 hours The three regimes of a training pointProof · Advanced · 30 min The soft-margin SVM is regularised hinge-loss minimisationProof · Intermediate · 30 min Solve a two-point SVM by handNumerical · Beginner · 30 min The SVM margin boundProof · Graduate · 1 hour Implement SMO for the SVM dualCoding · Graduate · 1 dayReferences
- PaperBernhard E. Boser, Isabelle M. Guyon and Vladimir N. Vapnik (1992). A Training Algorithm for Optimal Margin Classifiers
- PaperCorinna Cortes and Vladimir Vapnik (1995). Support-Vector NetworksThe soft-margin formulation.
- BookBernhard Schölkopf and Alexander J. Smola (2002). Learning with Kernels
- PaperJohn C. Platt (1998). Sequential Minimal Optimization
- BookIngo Steinwart and Andreas Christmann (2008). Support Vector Machines
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- PropositionThe geometric marginproof includedThe distance from a point to a hyperplane is the functional margin divided by the norm of the weight vector.
- PropositionThe hard-margin primal is a well-posed convex programproof includedScaling invariance is removed by the canonical normalisation, giving a strictly convex quadratic program.
- TheoremThe hard-margin SVM dualproof includedMaximise the sum of multipliers minus a quadratic form in the labelled Gram matrix, subject to non-negativity and a label-balance constraint.
- CorollarySupport vectors and complementary slacknessproof includedOnly points exactly on the margin can have non-zero multipliers, so the solution depends on those points alone.
- TheoremThe soft-margin SVM dualproof includedThe same dual with the multipliers box-constrained above by C; the slack variables disappear entirely.
- PropositionThe three regimes of a training pointproof includedEvery point is interior, on the margin, or a margin violator, determined by its multiplier.
- PropositionThe soft-margin SVM is regularised hinge-loss minimisationproof includedEliminating the slack variables turns the constrained program into an unconstrained convex objective.
- TheoremMargin-based generalisation boundproof includedThe risk is controlled by the empirical margin loss plus a term depending on the margin and the data radius, with no dimension dependence.
- Empirical observationWhy SVMs are no longer the defaultThe cubic cost in the sample size, not a theoretical deficiency, is what displaced them.
Problems (8)
All problems- Derive the hard-margin SVM dualProofGraduate⏱ 3 hours
- Derive the soft-margin SVM dualProofGraduate⏱ 3 hours
- The soft-margin SVM is regularised hinge-loss minimisationProofIntermediate⏱ 30 min
- Implement SMO for the SVM dualCodingGraduate⏱ 1 day
- The three regimes of a training pointProofAdvanced⏱ 30 min
- The SVM margin boundProofGraduate⏱ 1 hour
- The geometric marginProofFoundation⏱ 15 min
- Solve a two-point SVM by handNumericalBeginner⏱ 30 min