Support Vector Machines
A classifier that does not just separate two groups but separates them by the widest possible corridor. The width is set by a handful of borderline points, and everything else in the dataset is ignored.
Prerequisites: The Supervised Learning Framework, Convex Optimization
Draw two clouds of points on paper, one class each, well apart. Now draw a line that separates them. You will find you can draw infinitely many — nudge yours a little and it still works. Most classifiers pick one arbitrarily: once every point is on the right side, nothing is left to optimise. Support vector machines add the missing criterion: of all the lines that separate the classes, take the one that leaves the widest empty corridor on either side.
The intuition is a border dispute. Two villages need a boundary. Any line in the gap between them technically works, but the sensible surveyor puts it down the middle of the no-man's-land, because then a small error in anyone's map does not suddenly put a farmhouse in the wrong country. The width of that no-man's-land is the margin, and maximising it is the entire idea of an SVM.
The maths, one symbol at a time
A linear classifier scores a point with , where is a vector of weights (it points perpendicular to the boundary) and is an offset that slides the boundary back and forth. You predict class when the score is positive and when it is negative, so the boundary itself is where the score is zero.
Scores can be rescaled freely, so fix the units by demanding that the closest points on each side score exactly . Every training point must then satisfy
which says in plain English: every point is on its own side, and no closer to the boundary than the corridor edge. Under that convention the corridor width works out to , so making the margin wide means making small. The SVM is therefore
— shrink the weights as far as the "everyone stays outside the corridor" rules allow. It is a convex problem, so there is one answer and no local minima to worry about.
Only the points sitting on the corridor edge matter. These are the support vectors. Delete every other training point and refit: you get the identical boundary. This is why an SVM can be trained on ten thousand rows and remembered in a dozen.
Worked example 1: two points
Put a negative point at and a positive point at . By symmetry must point along , so write . The two constraints hold with equality at the support vectors:
The second rearranges to . Subtracting it from the first gives , so and . The boundary is , the perpendicular bisector of the two points. Its margin is
which is exactly the distance between the two points — the corridor fills the whole gap, as it should.
Worked example 2: what C buys you
Real data overlaps, so the hard constraint is relaxed. Each point gets a slack measuring how far inside the corridor it strays, and the objective becomes . The knob is the fine per unit of trespass.
Add a third point, , labelled positive — it sits dead on the old boundary, scoring . Its slack is . Two options:
- Keep the wide corridor and pay the fine. Cost .
- Tighten the corridor so nobody trespasses. Making a support vector gives , , no slack, and a cost of . The margin shrinks to .
With the first costs against , so the SVM shrugs and keeps the wide street. With it costs , so the SVM contorts to accommodate one point. Small means a smooth boundary that tolerates noise; large means a boundary that chases outliers. Slide the flexibility control below and watch that trade-off happen.
What this means in practice
The constraint form of the objective is equivalent to minimising hinge loss, , plus a size penalty — so an SVM is plain Empirical Risk Minimization with a particular loss. Rewriting the problem in its dual form makes the data appear only through inner products, which is the door to the The Kernel Trick and Kernel Methods and to curved boundaries at linear cost. On desks, SVMs earn their keep where features outnumber observations — text and sentiment classification, small labelled event studies — because the margin criterion degrades gracefully in high dimensions.
An SVM outputs a signed distance, not a probability. Feeding that score into a Kelly-style sizing rule as though it were is a real and common error; you must calibrate it first. And because the objective measures distance, unscaled features break it — a feature quoted in basis points and one quoted in units will not contribute comparably. Standardise before fitting, always.
Related concepts
Practice in interviews
Further reading
- Cortes & Vapnik, Support-Vector Networks (1995)
- Hastie, Tibshirani & Friedman, The Elements of Statistical Learning (Ch. 12)
- Bishop, Pattern Recognition and Machine Learning (Ch. 7)