Naive Bayes Classifier (30 — day NLP challenge)
Day 10
Naive Bayes Classifier (30 — day NLP challenge)
Day 10

Naive Bayes is a probabilistic classifier based on Bayes ' theorem with the assumption of independence b/w features.
Despite its simplicity, Naive Bayes has been widely used in various applications, including spam filtering, sentiment analysis, and document classification.
Fromula :

core naive bayes

Expanded Naive Bayes Formula
Simple Example of Naive Bayes in NLP

New Sentence to Predict
We want to know: “free cash” Is this Spam or Ham?
Step 1 — Count Classes
Total sentences = 4
- Spam = 2
- Ham = 2
So:
P(Spam) = 2/4 = 0.5
P(Ham) = 2/4 = 0.5
Step 2 — Word Frequency
Spam Words
free, money, offer, win, cash, now
Ham Words
let’s, meet, tomorrow, how, are, you
Step 3 — Check Words in New Sentence
Sentence:
Both words:
- “free”
- “cash”
appear in Spam sentences.
They do not appear in Ham sentences.
Step 4 — Probability Comparison
Spam
P(Spam | free cash)
= P(free | Spam) × P(cash | Spam) × P(Spam)
High probability because both words exist in Spam data.
Ham
P(Ham | free cash)
= P(free | Ham) × P(cash | Ham) × P(Ham)
Very low probability because words are absent in Ham data.
Final Prediction
New Sentence to Predict: “free cash”
We want to know: Is this Spam or Ham?
Step 1 — Count Classes
Total sentences = 4
- Spam = 2
- Ham = 2
P(Spam) = 2/4 = 0.5 P(Ham) = 2/4 = 0.5
Step 2 — Word Frequency
Spam Words: free, money, offer, win, cash, now
Ham Words: let’s, meet, tomorrow, how, are, you
Step 3 — Check Words in New Sentence
Sentence: free cash
Both words:
- “free”
- “cash”
appear in Spam sentences. They do not appear in Ham sentences.
Step 4 — Probability Comparison
Spam:
P(Spam | free cash) = P(free | Spam) × P(cash | Spam) × P(Spam)
High probability because both words exist in Spam data.
Ham:
P(Ham | free cash) = P(free | Ham) × P(cash | Ham) × P(Ham)
Very low probability because words are absent in Ham data.
Final Prediction
Result: “free cash” → Spam
Types of Naive Bayes
- Multinomial Naive Bayes
- Bernoulli Naive Bayes
- Gaussian Naive Bayes
메타데이터
- post_id
- 6bc0d910ec60
- slug
- naive-bayes-classifier-30-day-nlp-challenge-6bc0d910ec60
- url
- https://medium.com/@krisha22102005/naive-bayes-classifier-30-day-nlp-challenge-6bc0d910ec60
- canonical_url
- https://medium.com/@krisha22102005/naive-bayes-classifier-30-day-nlp-challenge-6bc0d910ec60
- author_url
- https://medium.com/@krisha22102005
- status
- ok
- fetched_at
- 2026-06-21 15:33:18