Spam or Not?
Label emails, build a word-frequency table, and train a real NaΓ―ve Bayes classifier β the same algorithm that powers Gmail's spam filter!
How NaΓ―ve Bayes Works
Collect Examples
Label emails as Spam or Ham (not-spam). These become your training data.
Count Word Frequencies
Count how often each word appears in spam vs ham emails. "Free" appears more in spam!
Calculate Probabilities
P(spam|email) = P(word1|spam) Γ P(word2|spam) Γ β¦ Γ P(spam). Bayes' theorem!
Classify
Whichever probability is higher β spam or ham β wins. That's the prediction!
Step 1 β Label the Training Emails
0 / 12 labelledπ Labelling Progress
Step 2 β Word Frequency Analysis
π΄ Top Spam Words
π’ Top Ham Words
Step 3 β Test the Spam Filter
0 / 8 testedKey evidence words
π§ͺ Test Results
Accuracy Report
Spam Hunter Badge!
You trained a NaΓ―ve Bayes classifier from scratch and evaluated its performance!
Optional. Stays on this device only β not sent to WhizzStep.
Key Concepts Mastered
π² The Algorithm
Assumes each word contributes independently to spam probability. "NaΓ―ve" because real words aren't independent β but it still works great!
π Base Rate
P(spam) = fraction of spam in training data. If 6 of 12 emails are spam, P(spam) = 0.5.
β Handling Zeros
What if a word never appeared in training? We add +1 to every count so probabilities are never zero.
βοΈ The Trade-off
High precision = few false alarms. High recall = catch all spam. F1 score balances both!
π’ Avoiding Underflow
Multiplying many tiny probabilities gives near-zero. We add log probabilities instead β same result, no underflow!
π Where It's Used
Gmail, Outlook, Yahoo Mail, and almost every email service uses NaΓ―ve Bayes as a first-pass spam filter.
About this lab
Learning objective: Test a simplified spam filter on sample messages and see which words push its decision.
What this simplifies: A small rule/keyword-weighted model is used; real spam filters combine many more signals.
Privacy: No learner input leaves the device.
Teacher prompt: Ask the class why this simulation might mislead someone who takes it too literally.
Reflect: What is one thing this activity showed you that you did not expect?
β Back to all Labs