University project · Data mining
Can a computer spot spam from the subject line alone?
Inventing simple spam indicators for 200 email subject lines, then letting a decision tree and a neural network learn from them. Both got it right about 85% of the time.
At a glance
- Type
- Lab exercise, team of two
- Period
- Winter semester 2021/22
- Data
- 200 email subject lines, labelled spam or not spam
- Methods
- C5.0 decision tree, neural network (multilayer perceptron)
- Tools
- IBM SPSS Modeler
About
A lab exercise in the course Information Retrieval Technology, part of the master's programme Technology and Innovation Management at Hochschule Harz, completed with a fellow student in the winter semester 2021/22.
The task
We got a table of 200 email subject lines. Each one was marked as spam or not spam: 107 were spam, 93 were real messages. The question was whether a computer could learn to tell them apart, using only the subject line.

A computer cannot read a subject line the way we do. It needs numbers. So the first job was ours: invent measurable signs, called indicators, that might give spam away.
Inventing the indicators
Look at a few real spam subjects and patterns jump out. They are often long, try to squeeze in many words, and use odd characters to slip past filters. A real message is usually short and plain, like “Meeting on Tuesday”.
So we added indicator columns to the table, including:
- Number of characters in the subject line.
- Number of words.
- Special characters, such as symbols that normal subjects rarely contain.
Then we gave the table to two different methods and compared how well each one learned.
Method 1: a decision tree
A decision tree works like a game of twenty questions. It asks the most useful yes or no question first, for example “Does the subject contain a special character?”, then splits the emails into two groups and keeps asking questions inside each group.
We built the tree with the C5.0 method in IBM SPSS Modeler. It classified 172 of the 200 emails correctly, 86%. Of the 93 real messages, 17 were wrongly marked as spam, about 18%.
The tree also shows which questions mattered most. The length of the subject line was the strongest sign, then the number of words, then special characters.

Method 2: a neural network
A neural network learns differently. Instead of clear questions, it adjusts weights, small dials that decide how much each indicator counts, until its answers match the labels as closely as possible.
SPSS Modeler built a multilayer perceptron with a single neuron in its hidden layer. Because of that hidden layer, it is not a simple perceptron, even if it is the smallest possible step beyond one. It classified 170 of the 200 emails correctly, 85%, and wrongly marked 14 of the 93 real messages as spam, about 15%.

Comparing the two
| Decision tree (C5.0) | Neural network | |
|---|---|---|
| Correct overall | 172 of 200 (86%) | 170 of 200 (85%) |
| Real messages marked as spam | 17 of 93 (18%) | 14 of 93 (15%) |
| Can you see why it decided? | Yes, every question is visible | Hardly, it is a set of weights |
The overall scores are almost the same. The interesting difference is the kind of mistake. The network wrongly flagged fewer real messages, which matters more than it sounds: a spam message in your inbox is annoying, but an important email lost in the spam folder can cost you a job offer.
What I took from it
Most of the work was not the algorithm. It was deciding what to measure. With a few simple indicators, both methods reached about 85%, and a better indicator would likely help more than a cleverer model. The tree also taught me the value of a result you can explain: when someone asks why an email was blocked, “the subject was very long and had special characters” is an answer people can check and trust.
Sources
- Wikipedia: Decision tree learning ↗en.wikipedia.org
- Merriam-Webster: spam, word history ↗merriam-webster.com
Get in touch
Questions, ideas, or tried something similar yourself? I'd love to hear about it. Email me