Part V — Non-Linear Models, Trees, Ensembles & Kernel Methods · Chapter 7

Support Vector Machines (SVM)

Hook

Infinitely many lines can separate two well-clustered classes. Is any one of them actually the best choice?

Intuition
Street width = 2.43

Drag either end of the line. As long as it separates the two classes, two dashed lines appear on either side — the "street," bounded by whichever point on each side sits closest. Push either end too far and the street vanishes: the line is now cutting through a class instead of separating it.

Formalize
  1. Maximize the margin

    A support vector machine picks the one separating line that makes this street as wide as possible.

  2. Support vectors touch the edges

    Whichever points end up touching the edges of that street — often just one or two per class — are the support vectors: the only points that determine the line at all.

  3. Only support vectors matter

    Move any other point further from the boundary and nothing changes; move a support vector and the whole line shifts.

Play
marginA = 1.76, marginB = 0.82, width = 2.57

Now both edges are measured separately. An off-center line has a wide gap on one side and a thin one on the other — the street is only ever as wide as its narrower side. Widening the narrow side (even at the cost of the wide side) is how the street actually grows.

Worked example
  1. Find the closest pair and their distance

    (3,6)(3,6) from one class and (5,4)(5,4) from the other:

    (53)2+(46)2=8=222.83\sqrt{(5-3)^2+(4-6)^2} = \sqrt{8} = 2\sqrt{2} \approx 2.83
  2. Find their perpendicular bisector
    1. Slope of the segment between them: (46)/(53)=2/2=1(4-6)/(5-3) = -2/2 = -1
    2. Perpendicular slope (negative reciprocal): +1+1
    3. Midpoint: ((3+5)/2, (6+4)/2)=(4,5)((3+5)/2,\ (6+4)/2) = (4,5)
    4. Line through (4,5)(4,5) with slope 11: y5=1(x4)    y=x+1y-5=1(x-4) \implies y=x+1
  3. Confirm it's the widest street

    Every other point sits comfortably further from this line than (3,6)(3,6) and (5,4)(5,4) do — so the street's width is set entirely by this one pair, and it equals exactly the distance between them, 222.832\sqrt{2} \approx 2.83.

Checkpoint

Drag both ends of the line to separate the two classes with the widest possible street — within 0.05 of the best possible width, 2.83.

Street width = 2.43
Drag either end of the line to try it
Summary

An SVM's line isn't just a separator — it's the one maximizing the margin to the nearest point of each class. That margin is set entirely by the support vectors; every other point could move (or vanish) without changing the answer at all. The next chapter asks what happens when no straight line can separate the classes in the first place.