Naïve Bayes Classifier
Naïve Bayes Classifier
🔍 What is Naïve Bayes?
The Naïve Bayes classifier is a supervised machine learning algorithm used for classification tasks. It is based on Bayes’ Theorem and predicts the class of a data point using probabilities.
👉 It is called:
- “Bayes” → because it is based on Bayes’ theorem
- “Naïve” → because it assumes independence between features
This means:
The presence of one feature does not affect the presence of another feature.
🧠 Core Idea
In classification, we want to compute:
👉 Probability of class given data
Using Bayes’ theorem:
🎯 Goal: Choose Best Class (MAP)
We compute probabilities for all classes and choose the maximum:
👉 This is called Maximum A Posteriori (MAP)
- We ignore because it is constant for all classes
⚙️ Why “Naïve”? (Key Assumption)
Instead of computing:
Naïve Bayes assumes:
👉 This simplifies computation drastically
📌 Important:
- This assumption is rarely true in real life
- But the algorithm still performs surprisingly well
📊 How Naïve Bayes Works (Step-by-Step)
1. 🧾 Calculate Class Probabilities (Prior)
Example:
-
If 50 out of 100 emails are spam:
2. 🔗 Calculate Conditional Probabilities (Likelihood)
For each feature:
Example:
👉 Calculated as:
3. 🧮 Compute Posterior for Each Class
4. 🏆 Choose Class with Maximum Probability
👉 Highest value = predicted class
📧 Example: Spam Detection
We want:
Interpretation:
-
→ Prior (how common spam is)P ( s p a m ) P(spam) -
P ( m o n e y ∣ s p a m ) → Likelihood (word “money” in spam) -
→ EvidenceP ( m o n e y ) P(money) -
P ( s p a m ∣ m o n e y ) → Final probability
👉 If:
➡️ classify as spam
⚡ Advantages
- ✅ Simple and easy to implement
- ✅ Very fast (good for real-time prediction)
- ✅ Works well for multi-class problems
- ✅ Excellent for text classification
Examples:
- Spam filtering
- Sentiment analysis
- Document classification
⚠️ Disadvantages
- ❌ Assumes feature independence (not realistic)
- ❌ Cannot capture relationships between features
📌 Types of Naïve Bayes
1. Gaussian Naïve Bayes
- For continuous data
- Assumes normal distribution
2. Multinomial Naïve Bayes
- For text data (word counts)
- Used in NLP tasks
3. Bernoulli Naïve Bayes
- For binary features
- Example: word present or not
🌍 Applications
- 📧 Spam detection
- 😊 Sentiment analysis
- 🏥 Medical diagnosis
- 💳 Credit scoring
- 🎯 Recommendation systems
💡 Final Insight
You can summarize Naïve Bayes as:
“Calculate probability of each class using Bayes’ theorem, assume features are independent, and pick the most probable class.”
Comments
Post a Comment