Machine Learning

Spam Classifier

The first layer below the waterline: instead of a human writing the rules, the program reads labelled examples and writes its own. This is Machine Learning. Messages become vectors of word weights (TF-IDF, with two-word phrases), and a Multinomial Naive Bayes model learns how much each word tips the odds toward spam. The whole thing trains in your tab when the page loads. Type anything and watch the verdict move with every keystroke.

Live classifier

Why it scored that way

Each present token's TF-IDF weight × its log-odds (spam vs ham). Red pushes toward spam, green toward ham. Words the model never saw during training are ignored.

type something above.

Training report

training…

Held-out test set

Dataset (24 messages)

How it works

Every message is tokenised into lower-case words and adjacent word pairs, and each token gets a TF-IDF weight: how often it appears in this message, discounted by how many messages contain it at all, so "the" counts for nothing and "prize" counts for a lot. Naive Bayes then treats a message as a bag of independent tokens and asks, for each class, how likely this bag would be if the message were spam versus ham, multiplied by how common each class is; the "naive" part is pretending the words are independent, which is false and works anyway. Training is just counting: sum the token weights inside each class, smooth with one pseudo-count per token, and take logs. At prediction time the two log-scores are compared and squashed into a confidence. With 24 examples the model is really learning vocabulary, not language, which is exactly why the live box is more honest than the accuracy number.