Gradient LabStart the lesson

Lessons › Chapter 4: Classification

Support vector machines

A support vector machine picks the line with the most breathing room on both sides, like the middle of the widest possible street between the groups. That gap is the margin. A wide margin leaves room for new points that land a bit off.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

A safe margin

For flagging fraud, Maya wants a boundary with room to spare, not one that only just separates the cases.

Problem

Many lines would work

These two groups can be split by lots of different lines. All three dashed lines get every training point right. But which one will do best on new points?

Key idea

Pick the widest street

A support vector machine picks the line with the most breathing room on both sides, like the middle of the widest possible street between the groups. That gap is the margin. A wide margin leaves room for new points that land a bit off.

Build

Support vectors

Only the points touching the edges of the street matter. They “support” the line, so they’re called support vectors. Move any other point a little and the line doesn’t change at all.

Problem

When no line works

Now one group sits inside the other. No straight line on this flat map can separate them.

Insight

Lift it up: the kernel trick

Give every point a height based on how far it is from the center. The outer ring rises, the inner group stays low. Now a flat sheet slides cleanly between them. This is the idea behind the kernel trick: add a dimension, then cut straight. (Real SVMs do this with a shortcut formula, without ever computing the new dimension.)

Real life

In real life: quality checks on a factory line

Factories measure parts as they pass (weight, width, shine) and separate good from faulty. A boundary with a wide safety margin is less likely to wave through a part that’s only just out of spec.

Quick check: Which line does an SVM choose?

It maximizes the gap to the nearest points on each side, which tends to generalize best.

Pseudocode

# many lines can split the two groups
# SVM picks the one with the widest gap on both sides

line = the line with the biggest margin
support_vectors = the points touching the margin edges

# curvy data? lift it into a new dimension first
height = distance_from_center²
then split with a flat sheet

Key terms

margin
The empty gap between the dividing line and the nearest points.
support vectors
The few points right at the edge of the margin. They decide where the line goes.
kernel trick
A shortcut that lets a model separate data as if it had been lifted into extra dimensions, so a flat cut works there, without computing those dimensions.