07_Naive_Bayes
Tags: #◇CSINTSY #◇Computational Thinking #◇Computer Science #◇Artificial Intelligence #◇Machine Learning #◇Intelligent Systems #◇Probability #◇Data Analysis
◇Overview
Naive Bayes is a probabilistic classifier based on Bayes' Theorem. It is called "Naive" because it makes a strong assumption that features are inde...
◇Details / Theory
7. Naive Bayes Reviewer
◇Overview
Naive Bayes is a probabilistic classifier based on Bayes' Theorem. It is called "Naive" because it makes a strong assumption that features are independent of each other given the class. Despite this simplification, it works surprisingly well, especially for text classification (e.g., Spam Filtering).
◇Bayes' Theorem
: Posterior Probability. The probability of Class given features . (What we want to find). : Likelihood. The probability of features appearing given Class . : Prior Probability. The initial probability of Class (before seeing data). : Evidence. The probability of features appearing. (Usually ignored in comparison since it's constant for all classes).
◇The "Naive" Assumption
We assume features are independent.
◇Classification Rule
To classify a new instance , we calculate the score for each class and pick the highest one:
◇Example: Spam Filter
Classes: Spam, Ham (Not Spam). Message: "Free Money". Calculation:
Compare scores. If , classify as Spam.
◇Laplace Smoothing (Add-One Smoothing)
Problem: If a word (feature) never appears in the training data for a specific class, its probability will be 0. Consequence: Since we multiply probabilities, a single 0 will make the entire score 0, regardless of other evidence. Solution: Add a small count (usually 1) to all frequency counts.
: Vocabulary size (total number of unique words).
This ensures no probability is ever exactly zero.
◇Solved Example: Spam Classification
Dataset:
Spam (3 messages): "Buy cheap meds", "Cheap money", "Buy money" Ham (2 messages): "Cheap meds", "Study hard"
Vocabulary: {Buy, Cheap, Meds, Money, Study, Hard} (Size )
Priors:
Likelihoods (with Laplace Smoothing +1):
Spam Word Count: 6 words total.
Count("Cheap" | Spam) = 2.
Count("Money" | Spam) = 2.
Ham Word Count: 4 words total.
Count("Cheap" | Ham) = 1.
Count("Money" | Ham) = 0.
Test Message: "Cheap Money"
Calculate Scores:
-
Spam Score:
-
Ham Score:
Conclusion:
Since , the message is classified as Spam.
◇Common Pitfalls
Forgetting Laplace smoothing when a feature value has zero occurrences in a class — without it, the entire probability becomes 0. Violating the "naive" independence assumption without awareness — Naive Bayes assumes features are conditionally independent given the class. Comparing raw products instead of normalizing — final classification compares across all classes.
◇Summary
TL;DR — Naive Bayes classifies by computing for each class and picking the maximum. It assumes feature independence and uses Laplace smoothing to handle zero-count features.
◇Links
Related: Source / Reference:
Made by 2ru17
Please contact me through discord or my the university email for any problems regarding the reviewer. Thanks!
◇References & Navigation
- Previous Topic: ◇Decision Tree
- Next Topic: ◇K Means Clustering
- Related Notes: ◇Naive Bayes
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
Why is the Naive Bayes classifier called "Naive"?
In Bayes' Theorem, what does the term represent?
Which term in Bayes' Theorem describes the probability of observing the features given a specific class, ?
When computing probabilities for different classes, why is the Evidence term often ignored?
How does Naive Bayes mathematically represent its independence assumption?
How does a Naive Bayes classifier finally determine the predicted class for a new instance?
What problem arises if a word in a test instance never appeared in the training data for a specific class?
What technique is used to solve the zero-probability problem in Naive Bayes?
In the context of Laplace smoothing, what does the variable represent in the formula?
If an email classification dataset has 10 Spam messages and 40 Ham messages, what is the Prior Probability of Spam, ?