Label emails, build a word-frequency table, and train a real NaΓ―ve Bayes classifier β the same algorithm that powers Gmail's spam filter!
Label emails as Spam or Ham (not-spam). These become your training data.
Count how often each word appears in spam vs ham emails. "Free" appears more in spam!
P(spam|email) = P(word1|spam) Γ P(word2|spam) Γ β¦ Γ P(spam). Bayes' theorem!
Whichever probability is higher β spam or ham β wins. That's the prediction!
You trained a NaΓ―ve Bayes classifier from scratch and evaluated its performance!
Assumes each word contributes independently to spam probability. "NaΓ―ve" because real words aren't independent β but it still works great!
P(spam) = fraction of spam in training data. If 6 of 12 emails are spam, P(spam) = 0.5.
What if a word never appeared in training? We add +1 to every count so probabilities are never zero.
High precision = few false alarms. High recall = catch all spam. F1 score balances both!
Multiplying many tiny probabilities gives near-zero. We add log probabilities instead β same result, no underflow!
Gmail, Outlook, Yahoo Mail, and almost every email service uses NaΓ―ve Bayes as a first-pass spam filter.