25 November 2026 · 3 min readInteractive 3D
How does a spam filter draw a line?
Sorting things into two groups can be as simple as placing a flat wall between them. Move the wall yourself and watch the score.
A spam filter has to answer one question about each email: spam or not? One of the simplest ways to answer is to describe each email with a few numbers and then place a flat wall in that space. Emails on one side are spam; on the other, not.
Turn, tilt, slide
A flat wall in 3D needs only a few numbers: which way it faces and where it sits. In the model those are the turn, the tilt and the slide. A linear classifier is just those numbers, and training means finding the values that put the most dots on the right side.
Where the numbers come from
- How many times words like “free” or “winner” appear.
- How many links the email contains.
- Whether the sender is in your contacts.
Real filters use hundreds of such numbers, so the wall lives in hundreds of dimensions. The idea is identical.
Try to get 100%. If the two clouds overlap at all, you cannot: some emails really do look like spam. That is why no filter is perfect.
A worked example
A filter looks at two numbers for each email: how many times “free” appears (f) and how many links it has (l). It calls an email spam if 2f + l − 6 > 0.
- Email A: f = 3, l = 2 → 6 + 2 − 6 = 2 > 0 → spam
- Email B: f = 0, l = 4 → 0 + 4 − 6 = −2 → not spam
- Email C: f = 2, l = 2 → 4 + 2 − 6 = 0 → right on the line
The line 2f + l = 6 divides the plane in two. With three features it becomes a flat plane in 3D, and with more features a “hyperplane” we cannot draw but can still compute with.
Measuring how well it works
Accuracy is the share of emails classified correctly, but it can mislead. If 99% of emails are not spam, a filter that never flags anything is 99% accurate and useless. Precision (of the emails flagged, how many really are spam) and recall (of the real spam, how much was caught) tell the full story.
Learning the line
The weights 2, 1 and −6 are not chosen by hand. A learning method such as logistic regression starts with random weights and nudges the line every time it misclassifies an example, until mistakes are as few as possible.
Real spam filters use thousands of features, but many still rely on a linear model at their core because it is fast and easy to check.
Logistic regression
Instead of a hard yes or no, logistic regression passes the score through a sigmoid to get a probability. A score of 0 gives 50%, a score of 3 gives about 95%. You can then choose the threshold: a hospital might flag anything above 20% for a second look, while a spam filter might wait for 90%.
Glossary
- Decision boundary: where the score is exactly zero.
- Threshold: the cut-off for saying yes.
- False positive: wrongly saying yes.
- False negative: wrongly saying no.
Try these yourself
- Q1. Rule 2f + l − 6 > 0: f = 1, l = 5? 2 + 5 − 6 = 1, spam
- Q2. 90 spam flagged, 10 wrongly flagged: precision 90%
- Q3. 100 real spam, 80 caught: recall 80%
- Q4. With 3 features, the boundary is a … plane
In short
A linear classifier scores each example with weights and checks which side of a line or plane it falls on. Judge it by precision and recall, not accuracy alone.
Keep going
Questions people ask
What is a linear classifier?
A model that separates two classes with a straight line, flat plane or hyperplane, deciding by which side a point falls on.
How does a spam filter decide?
It scores each email from its features with learned weights and marks it as spam if the score is above a threshold.
What is the difference between precision and recall?
Precision is how many flagged items were truly positive; recall is how many true positives were found.