ML0091 Naive Bayes Types

What are the different types of Naive Bayes classifiers (Gaussian, Multinomial, Bernoulli), and when is each appropriate for tasks like Microsoft’s spam filtering or medical diagnosis?

Answer

The three main variants of Naive Bayes differ in the distribution they assume for each feature given the class, and the choice is driven by the feature type. Gaussian Naive Bayes assumes each continuous feature follows a normal distribution per class, estimated by the class-conditional mean and variance; it suits real-valued features like medical lab values or sensor readings. Multinomial Naive Bayes models integer feature counts drawn from a multinomial distribution, and in practice TF-IDF weights are often substituted even though they are not counts; it is the standard for text classification, used in Microsoft’s spam filtering training module and production review-spam detection processing 85,000 reviews per day. Bernoulli Naive Bayes models binary presence/absence indicators with a Bernoulli distribution; it suits boolean features like “contains word X” or “has flag Y” and explicitly accounts for the absence of a feature, which Multinomial NB does not.

(1) Gaussian NB (Continuous): estimates \mu_{yj} and \sigma_{yj}^2 per class per feature; best for real-valued features like blood pressure, age, or sensor readings; assumes normality, so skewed or multi-modal features need transformation or kernel density estimation.
(2) Multinomial NB (Count Data): estimates P(w_j \mid y) = (N_{yj} + \alpha) / (N_y + \alpha d); the standard for text classification on word counts, and commonly run on TF-IDF weights as a practical approximation; Microsoft’s training module uses it for email spam filtering, and a production system classifies 85,000 reviews/day at AUC above 0.99.
(3) Bernoulli NB (Binary Presence): estimates P(x_j = 1 \mid y) and explicitly models P(x_j = 0 \mid y); best for short documents or boolean feature sets where absence is informative; scikit-learn ships it alongside categorical and complement variants, and the R naivebayes package adds a Poisson variant for count features.

Three panels: Gaussian NB shows bell curves per class for a continuous feature; Multinomial NB shows a bar chart of word count probabilities per class; Bernoulli NB shows a binary presence/absence table with P(x=1|y) and P(x=0|y)

Figure 1: The three Naive Bayes variants: Gaussian models continuous features as per-class normal distributions, Multinomial models count data as a multinomial over a vocabulary, and Bernoulli models binary presence/absence with explicit absence probabilities.

The choice between Multinomial and Bernoulli for text depends on document length and whether absence carries information. Multinomial NB uses word frequencies, so a word appearing three times contributes three times the evidence; Bernoulli NB uses only presence, so “free” appearing once or ten times contributes the same amount, but the absence of “free” also contributes evidence. For long documents where frequency matters (emails, articles), Multinomial is standard. For short documents where presence is the signal (search queries, short reviews), Bernoulli can match or beat Multinomial. A common production pattern is TF-IDF weighting with Multinomial NB, as in the Banking77 support ticket router that classifies 13,000 banking queries into 77 intents in under 1 ms per ticket. For mixed feature types (continuous plus categorical plus binary), scikit-learn does not natively combine variants, so practitioners either discretize continuous features or use the R naivebayes package which supports mixed distributions including kernel density estimation.

Mathematical Formulation:
P(x_j \mid y) = \frac{1}{\sqrt{2\pi\sigma_{yj}^2}} \exp\!\left(-\frac{(x_j - \mu_{yj})^2}{2\sigma_{yj}^2}\right)
P(x_j \mid y) = \frac{N_{yj} + \alpha}{N_y + \alpha\, d}
P(x_j \mid y) = \theta_{yj}^{x_j}(1 - \theta_{yj})^{1 - x_j}

Where:

  • The first equation is Gaussian NB: \mu_{yj} and \sigma_{yj}^2 are the mean and variance of feature j in class y, estimated from training data.
  • The second equation is Multinomial NB: N_{yj} is the count of feature j in class y, N_y is the total count, \alpha is Laplace smoothing, and d is the vocabulary size.
  • The third equation is Bernoulli NB: \theta_{yj} = P(x_j = 1 \mid y) is the probability that feature j is present in class y; the term (1 - \theta_{yj})^{1 - x_j} explicitly models the absence of the feature.
VariantFeature TypeDistributionBest For
Gaussian NBContinuous (real-valued)Normal per classMedical diagnosis, sensor data, Iris dataset
Multinomial NBCounts or TF-IDFMultinomialEmail spam, review classification, ticket routing
Bernoulli NBBinary presence/absenceBernoulliShort text, boolean features, spam with word presence

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *