Support vector machines
How a support vector machine picks the one line that leaves the widest gap between two groups, tolerates a stray point, and bends into a curve with the kernel trick.
In 30 seconds
A support vector machine (SVM) separates two groups of points with a line, and of all the lines that work it picks the one with the widest empty margin on both sides.
Only the few points on the edge of that margin, the support vectors, decide where the line goes. A soft margin lets the odd point break the rule for a penalty.
When no straight line fits, the kernel trick has the SVM work as if the points were lifted into a space where one does, which gives a curved boundary back home.
Support vector machines, step by step
Two features keep it drawable; with more, the line becomes a plane or hyperplane. Slack is counted on the score scale (1.5 here), and real solvers find the line by optimisation, not by eye.
- Step 1: Which line is best?. Ten labelled points, two classes. A classifier here is a straight line with red on one side and blue on the other. Lines A, B and C all manage it, but A and B brush past some points, so a slightly different new point could land on the wrong side.
- Step 2: The widest street. A support vector machine picks the line with the widest empty street around it: the maximum margin. Here that is x + y = 6, with a street 2.83 wide. A new point is classified by the sign of its score, and a wide street leaves the most room for error.
- Step 3: Support vectors. Only the points sitting on the edges of the street decide where it goes. These are the support vectors: two red, one blue. The other seven points could be deleted, or moved around on their own side of the street, and the line would not change.
- Step 4: Soft margin. Real data is messy. A stray red point at (3.5, 3.5) would force a strict SVM to squeeze the street to 0.71 wide. A soft margin lets a point break the rule at a price: its slack, times a setting C. With C = 1 the wide street costs 1.75 against 4, so it stays.
- Step 5: When no line works. Some data cannot be split by any straight line, however soft the margin. Here red points sit in the middle and blue points surround them. Any line with all the red points on one side has blue points on that side too.
- Step 6: Lift, cut, drop back. Add a third number to every point: z = x² + y², its squared distance from the centre. Plotted against z, red sits low and blue sits high, and a flat maximum-margin cut at z = 2.5 separates them. Back in the plane that flat cut is a circle of radius 1.58.
- Step 7: The kernel trick. An SVM never needs the lifted points themselves, only dot products between pairs of them. A kernel gives that number straight from the original coordinates. Here (a · b)² equals the dot product after lifting to (x², √2·xy, y²), which holds the squares the circle needed. Other kernels stand for lifts too large to write out.
Try it yourself
Learn this first
Spotted a mistake on this page?