Support vector machine (SVM)

Supervised · Classification An SVM finds the boundary that separates two groups with the widest possible margin, the biggest empty gap on both sides. The points closest to the boundary are called support vectors, because they alone decide where it goes. When groups can't be split by a straight line, the kernel trick lets SVM draw curved boundaries.

Everyday analogy

Building the widest possible road between two villages, so houses on both sides stay as far from the traffic as possible.

Example

Used for: text and document classification, handwriting recognition, image classification, classifying genes and proteins.

widest gap
An SVM draws the dividing line with the widest possible safety gap between the groups.

The widest gap between two groups

widest marginRinged points = support vectors

How it works, step by step

  1. Plot the labelled examples as points.
  2. Look at all the lines (or planes) that could separate the two groups.
  3. Choose the one with the widest margin to the nearest points on each side.
  4. If no straight line can separate them, use a kernel to map the data into a higher dimension, where a clean split is possible.
  5. Classify a new point by which side of the boundary it falls on.

Worked example

Sorting customer emails into "complaint" and "enquiry". Each email becomes a point based on its words. The SVM finds the boundary with the widest gap between the two kinds, so even new emails with unusual wording are usually sorted correctly.

✓ Good for

  • Accurate on small and medium datasets
  • Works well with many features, such as text
  • The wide margin helps it generalise to new data

⚠ Watch out for

  • Slow on very large datasets
  • Hard to explain individual decisions
  • Choosing the right kernel and settings takes care

Try it yourself

About 10 min

Draw the widest gap

  1. On paper, draw 6 dots of one colour on the left and 6 of another on the right.
  2. Draw several lines that separate them, then the one with the most space on both sides.
  3. Add a dot near the middle and see which line handles it best.

What you should see: SVM chooses the separating line with the widest safety margin.

Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.

Build it for real · guided projectFind customer groups with K-means clusteringAbout 45 min · Copy-paste code · step by step
Test what you learned

Take a quick quiz, or look up any word in the glossary.