Naive Bayes is a probabilistic classifier based on Bayes’ Theorem. It assumes conditional independence between features given the class.
Probabilistic Foundation: Bayes’ Theorem
We predict the class probability for an input feature vector using:
The Conditional Independence Assumption
Estimating directly requires massive datasets. The Naive Bayes classifier assumes that features are conditionally independent given the class:
Thus, the classification rule predicts the class that maximizes the numerator:
The “Naive” Limitation
Features are rarely independent in practice, making the model “naive” (e.g., “machine” and “learning” are highly correlated), but it performs remarkably well on tasks like spam filtering.
Generative vs. Discriminative
Naive Bayes is a generative model because it models the joint distribution , unlike discriminative models (e.g., Logistic Regression) which model directly.
Laplace Smoothing
If a feature value never occurs with class in training, the probability is . Since we multiply feature probabilities, this zeroes out the entire class probability. We prevent this using Laplace Smoothing:
where is the number of possible values for , and is the smoothing parameter.
Example: Classification with Gaussian Naive Bayes
The following example demonstrates training a Gaussian Naive Bayes model on continuous features:
Fit a Gaussian Naive Bayes classifier on continuous physical features and predict class probability distributions.
Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare
Exercise
Test your understanding of the independence assumption:
Knowledge Check
What is the main drawback of the Naive Bayes conditional independence assumption?
Answer: It assumes features contribute independently to the class, which hurts accuracy when features are highly correlated.
When features are highly correlated (e.g., word occurrences in phrases), the assumption that they are independent is false. This can lead the model to output overconfident or incorrect probabilities.
What is the main drawback of the Naive Bayes conditional independence assumption?
Prior Probabilities
Priors reflect baseline class rates, acting as regularizers that bias predictions toward dominant classes.