Text Classification using Multinomial vs Bernoulli Naïve Bayes (20 Newsgroups Dataset)
Experiment
Text Classification using Multinomial vs Bernoulli Naïve Bayes (20 Newsgroups Dataset)
🎯 Objective
-
To implement:
- Multinomial Naïve Bayes
- Bernoulli Naïve Bayes
-
To compare performance using:
- Accuracy
- F1-score
- To understand differences in text modeling
- learn about 20 News group Dataset
📚 Background
🔹 Naïve Bayes
🔹 Key Difference
| Model | Feature Type |
|---|---|
| Multinomial NB | Word counts |
| Bernoulli NB | Word presence (0/1) |
💻 Python Program
📊 Results
=== Multinomial NB ===
Accuracy: 0.9153976311336718
F1 Score: 0.9152700646053145
precision recall f1-score support
0 0.95 0.90 0.93 202
1 0.93 0.92 0.93 202
2 0.86 0.93 0.89 187
accuracy 0.92 591
macro avg 0.92 0.92 0.92 591
weighted avg 0.92 0.92 0.92 591
=== Bernoulli NB ===
Accuracy: 0.8477157360406091
F1 Score: 0.8474953519771379
precision recall f1-score support
0 0.96 0.84 0.90 202
1 0.72 0.98 0.83 202
2 0.95 0.71 0.81 187
accuracy 0.85 591
macro avg 0.88 0.84 0.85 591
weighted avg 0.88 0.85 0.85 591
🔍 Observations
🔹 Multinomial NB
- Uses word frequency
-
Performs better for:
- Long documents
- Rich vocabulary
🔹 Bernoulli NB
- Uses presence/absence
- Ignores word frequency
-
Works better when:
- Word occurrence matters more than count
📈 Key Differences
| Aspect | Multinomial NB | Bernoulli NB |
|---|---|---|
| Input | Counts | Binary |
| Captures frequency | ✅ Yes | ❌ No |
| Sparse data handling | Good | Very good |
| Text classification | Best choice | Alternative |
Results
-
Multinomial NB:
- Best for most text classification tasks
- Uses richer information
-
Bernoulli NB:
- Simpler
- Useful when only presence matters
Comments
Post a Comment