← CS Lab AI & Machine Learning / SVM Max-Margin Open standalone ↗

An SVM draws the straight line that splits two classes with the widest possible gap. Not just any dividing line — the one that keeps the biggest empty buffer on both sides.

Where you meet it

What it does

Many lines can separate two clean classes. The SVM picks exactly one: the line whose empty corridor between the classes is stretched as wide as it will go. A new point is then labelled by which side of the line it lands on. The wide buffer is the whole point — it leaves the most room for error on data you haven't seen yet.

Only a handful of borderline points decide the line — the rest of your data could vanish and it wouldn't move an inch.

How it works

The boundary is a line written as w · x + b = 0, and a point is classified by the sign of w · x + b — plus or minus tells you the side. The two edges of the corridor sit at +1 and −1, and their distance apart — the corridor width the tool shows — works out to 2/‖w‖. So "widest corridor" literally means "smallest w": that is the one quantity the SVM shrinks.

predict:   label = sign(w · x + b)      # which side of the line a point falls on

gap width = 2 / ‖w‖                     # a wider gap = a smaller w
goal:      make ‖w‖ as small as possible
rule:      yᵢ · (w · xᵢ + b) ≥ 1        # every point on its side, past the edge

Here yᵢ is just the label written as +1 or −1, so the one rule covers both classes at once. The points that end up sitting exactly on an edge are the support vectors — in a 2D case like this, usually just two or three. They alone pin the line down; w is built from them and nothing else. Picture sliding a ruler between two clumps of dots and widening a chalk stripe on each side until it just touches the nearest dot: the middle line is your boundary, the touched dots are the support vectors.

Watch out

  • Scale your features first. The margin is a distance, so a feature measured in thousands drowns out one measured in fractions. Standardise to mean 0, variance 1 — otherwise "widest gap" is measuring the wrong thing.
  • A support vector is a borderline point, not an outlier. It is the hardest case sitting right on the edge, not a far-flung stray.
  • Hard margin needs the classes to actually be separable by a line. One point on the wrong side and there is no solution. Real data overlaps, so practice uses a "soft" margin that tolerates a few violations (a dial called C).
  • If no straight line can split the data — a ring wrapped inside a ring — max margin alone can't help. That's the kernel trick, next door.

The whole model hangs on a few stubborn points at the border — find them and you've found the line.

Go deeper

Eine SVM zieht die Gerade, die zwei Klassen mit dem breitestmöglichen Abstand trennt. Nicht irgendeine Trennlinie — die mit dem größten leeren Puffer auf beiden Seiten.

Wo es vorkommt

Was es tut

Viele Linien trennen zwei saubere Klassen. Die SVM wählt genau eine: die, deren leerer Korridor zwischen den Klassen so weit aufgezogen ist wie es nur geht. Ein neuer Punkt bekommt dann sein Label danach, auf welcher Seite der Linie er landet. Der breite Puffer ist der ganze Sinn — er lässt den meisten Spielraum für Daten, die du noch nie gesehen hast.

Nur eine Handvoll Grenzpunkte bestimmt die Linie — der Rest deiner Daten könnte verschwinden, und sie würde sich keinen Millimeter rühren.

Wie es funktioniert

Die Grenze ist eine Gerade w · x + b = 0, und ein Punkt wird über das Vorzeichen von w · x + b zugeordnet — Plus oder Minus sagt die Seite. Die beiden Korridorränder liegen bei +1 und −1, und ihr Abstand — die Korridorbreite, die das Tool anzeigt — ergibt 2/‖w‖. "Breitester Korridor" heißt also wörtlich "kleinstes w": genau diese eine Größe zieht die SVM klein.

Vorhersage:  label = sign(w · x + b)     # auf welcher Seite der Linie ein Punkt liegt

Korridor  = 2 / ‖w‖                      # breiterer Korridor = kleineres w
Ziel:        ‖w‖ so klein wie möglich machen
Bedingung:   yᵢ · (w · xᵢ + b) ≥ 1       # jeder Punkt auf seiner Seite, hinter dem Rand

Dabei ist yᵢ nur das Label als +1 oder −1, damit die eine Bedingung beide Klassen auf einmal abdeckt. Die Punkte, die am Ende genau auf einem Rand sitzen, sind die Support-Vektoren — in einem 2D-Fall wie hier meist nur zwei oder drei. Sie allein pinnen die Linie fest; w entsteht aus ihnen und aus nichts sonst. Stell dir vor, du schiebst ein Lineal zwischen zwei Punktwolken und ziehst auf jeder Seite einen Kreidestreifen breiter, bis er den nächsten Punkt gerade berührt: Die Mittellinie ist deine Grenze, die berührten Punkte sind die Support-Vektoren.

Worauf achten

  • Erst die Features skalieren. Der Margin ist ein Abstand — ein Merkmal in Tausendern übertönt eines in Bruchteilen. Standardisiere auf Mittelwert 0, Varianz 1, sonst misst der "breiteste Abstand" das Falsche.
  • Ein Support-Vektor ist ein Grenzpunkt, kein Ausreißer. Er ist der schwerste Fall direkt am Rand, kein weit entfernter Irrläufer.
  • Hard-Margin setzt voraus, dass eine Gerade die Klassen wirklich trennt. Ein Punkt auf der falschen Seite, und es gibt keine Lösung. Echte Daten überlappen, darum nutzt die Praxis einen "weichen" Margin, der ein paar Verstöße erlaubt (ein Regler namens C).
  • Wenn keine Gerade die Daten trennt — ein Ring in einem Ring — hilft Max-Margin allein nicht. Das ist der Kernel-Trick, gleich nebenan.

Das ganze Modell hängt an ein paar sturen Punkten am Rand — findest du sie, hast du die Linie.

Mehr dazu

Next up
AI & Machine LearningSVM Kernel Trick AI & Machine LearningEntropy & Information Gain All concepts →