How Machines Learn to Classify 1 of 5
1
2
3
4
5

How Machines Learn to Classify

Interactive · about 10 minutes · 5 activities

Every time an AI labels something — spam vs. legitimate, cat vs. dog, pass vs. fail — it is doing classification. This lesson shows exactly how that works.

Step 1 — Each example becomes a dot

The trick that makes classification learnable is simple: turn every example into a point on a grid.

📏📐
2 measurements
links & caps count
📊
2 axes
x-axis & y-axis
1 dot
placed on the grid
🔴 🟢
dot color
= the correct label
Email spam example. Every email has two numbers: links (how many URLs) and caps words (how many ALL-CAPS words). Plot those two numbers and spam separates from legitimate mail into two clouds. The computer finds the line between the clouds.

The interactive plot below shows 60 emails already plotted. Hover or tap any dot to see the actual email stats that placed it there.

Activity 1 of 5 · Explore the data
Spam Legitimate

Hover a dot to inspect it →

Notice how the red cloud (spam) gathers toward the top-right — many links, many caps words — while the green cloud (legitimate) stays bottom-left. They overlap a little in the middle. That messy overlap is where classifiers make mistakes, and that is normal.

Step 2 — Sorting emails yourself

Before the machine learns, you try. For each email below, look at its two measurements and decide: spam or legitimate? You are doing exactly what the classifier will do.

Activity 2 of 5 · Classify 6 emails by hand

Where you hesitated — emails with mid-range link and caps counts — is precisely where any rule struggles. Those are the examples near the decision boundary.

Step 3 — The decision boundary

After seeing the labeled dots, the classifier draws an imaginary line (or curve) that puts as many green dots on one side and red dots on the other as possible. That line is the decision boundary.

Any new email dropped on the plot lands on one side of the line — and that side is its label. Drag the threshold slider below and watch the boundary move. See how accuracy changes as you adjust where the cut is made.

Activity 3 of 5 · Move the decision boundary
Spam Legitimate

Moving the boundary left catches more spam but also flags more legitimate mail as spam (false positives). Moving it right misses some spam but leaves legitimate mail alone. The "best" position depends on which mistake is more costly.

Step 4 — Classify new examples

A trained classifier should handle examples it has never seen. Click anywhere on the plot to drop a new email dot. The classifier predicts its label based on which side of the learned boundary it lands on.

Activity 4 of 5 · Click to add new dots
Spam Legitimate Your new dot

Click on the grid to classify a new email →

The axes are deliberately generic in the real lesson demonstration — they carry no particular units, because the procedure works the same regardless of what the two measurements actually are.

Step 5 — Check your understanding

Four quick questions to lock in the concepts.

Activity 5 of 5 · Quick check