Learning From Examples
You could write if subject contains "FREE" then spam and ship it, but the moment a spammer types "Fr€€" your rule is dead. There is a second way to build that filter, and it never touches a keyword list.
- ▸A hand-written spam rule catches only the spam you imagined; the moment junk mutates to "Fr€€", it's dead
- ▸You never write the winning rule; you grade a stack of examples and the machine finds the pattern
- ▸Every dataset is inputs plus one answer column; which column you pick as the answer changes what you predict
if subject contains "FREE" then spam. One line, and it even works, for a while. You add more lines as junk slips through: block WINNER, block $$$, block ACT NOW. Each new keyword catches yesterday's spam.
Then two things break at once. A real email from a shipping company says "free shipping on your order" and your filter dumps it in the junk pile. Meanwhile a spammer writes "Fr€€ M0ney" with funny characters and sails straight past every keyword you listed.
You can keep adding rules forever. Spam keeps mutating to dodge them, and every keyword broad enough to catch the disguises also flags honest mail that happens to use the same word. Hand-written rules can catch the spam you already thought of. They cannot catch the spam you have not seen yet.
The second way skips the keyword list entirely. Instead of writing rules, you collect a stack of past emails and mark each one: this is spam, this is not. That graded stack is your training examples. You hand the whole thing to the machine and it studies it.
What comes back is a model: a thing that learned the pattern separating the two piles. Nobody wrote that pattern down. It is not a keyword you can point to. It came out of the grades you supplied, the machine worked out the separating rule itself, the rule you could not write by hand.
Run that model over the same batch that beat your keyword filter and the mistakes nearly vanish. It catches Fr€€ M0ney because disguised spam still looks like the spam it studied, and it clears "free shipping" because that email looks like the honest mail it studied. The catch: the model is only as good as your grades. Mark real emails as spam by mistake and it faithfully learns your mistake.
To hand examples to a machine, you lay them out as a table: one row per email, one column per thing you measured about it. Number of links. Count of ALL-CAPS words. Whether the sender is in your contacts. Each of those input columns is a feature.
One column is different. It holds the answer you graded by hand, spam or not-spam. That answer column is the target, the thing you want the model to produce. Everything else is a feature it reads; the target is the single column it is trying to fill.
Which column is the target is a choice about your question, not a fact baked into the data. Point at "spam or not" and you are building a spam filter. Point instead at "will the reader click" and the very same table trains a different model. Pick the target first, and every other column becomes a feature feeding it.