Naive Bayes Classifier

Naive Bayes is a probabilistic classification model that represents the relationship between a class label and a set of features using a Bayes net with a single parent node. It is designed for supervised classification tasks, where each data point is represented by extracted features and an associated label.

The defining modeling assumption of Naive Bayes is conditional independence: all features are assumed to be independent of one another given the class label. Graphically, this corresponds to a Bayes net in which is the parent of every feature , with no edges between features. By the rules of d-separation, this implies

This assumption is strong—and often false in reality—but it drastically reduces the number of parameters needed to represent the joint distribution, making inference and learning computationally efficient.

For classification, the goal is to predict the most likely label given an observed feature vector . Using Bayes’ rule and dropping the normalization constant, Naive Bayes predicts:

The class prior captures how frequently each label appears, while the conditional probabilities capture how each feature behaves within a class. This decomposition is what makes Naive Bayes scalable even when the number of features is large.

The parameters of a Naive Bayes model are typically learned using maximum likelihood estimation (MLE) under the assumption that training examples are independent and identically distributed (i.i.d.). For Bernoulli features (e.g., whether a word appears in an email), the MLE for a conditional probability is simply the empirical frequency:

This results in simple count-based parameter estimation that scales linearly with the size of the training data.

A key limitation of pure MLE in Naive Bayes is overfitting, especially when certain feature–class combinations never appear in the training data, leading to zero probabilities and thus zeroed-out posteriors. To address this, Laplace smoothing is commonly applied. With smoothing strength k, probabilities are estimated as:

which can be interpreted as assuming k additional pseudo-counts of each possible outcome. Smoothing prevents zero probabilities and improves generalization to unseen data.