Ensemble Naive Bayes

Machine Learning
Introduced by
Various (Dietterich, T.G.; Webb, G.I.; others)
Year
2000s
Type
Ensemble of probabilistic classifiers
Family
Machine learning

What does it do?

Ensemble Naive Bayes trains several Naive Bayes classifiers, each on a different view of the data (bootstrap samples, feature subsets, feature partitions, or boosting-style reweighting), and combines their outputs.

In the standard formulation the combination is a weighted sum of member log-probabilities followed by an argmax; majority voting and probability averaging are common alternatives. The members keep the closed-form training and simple probabilistic structure of Naive Bayes, while aggregation aims to reduce the variance of individual fits.

The intuition behind the method

A single Naive Bayes classifier relies on a strong conditional independence assumption that is rarely exact in real data. Each member trained on a different sample or feature subset estimates the class-conditional probabilities from a somewhat different slice of the data, so the members' errors are partly uncorrelated. Combining their scores is intended to reduce the variance of the estimates, although whether this improves accuracy depends on the dataset and should be checked on held-out data. It does not remove the bias that comes from the independence assumption itself. The ensemble keeps the probabilistic form of Naive Bayes while smoothing out the fluctuations of any single fit.

History

The ensemble idea comes from the broader ensemble learning literature, which Dietterich (2000) reviews in general terms; that paper does not address Naive Bayes ensembles specifically. Separate work by Lowd and Domingos (2005) studies Naive Bayes models for general probability estimation rather than ensembles. The originators of Naive Bayes ensembles are not firmly established in this entry's sources.

When to use it

Choose Ensemble Naive Bayes when a Naive Bayes model is already a reasonable baseline for your data (categorical, count-based text, or simple continuous features) but a single model appears unstable, for example when estimates change noticeably across resamples of a moderate-sized training set. It is a natural candidate for text classification, where Multinomial NB is a strong baseline. Do not use it when the conditional independence assumption is clearly violated, especially for strongly correlated continuous features, because adding members does not correct that bias. Avoid it for very small datasets, where resampled members are likely to be too similar to add useful diversity, and when a gradient-boosted tree model clearly outperforms Naive Bayes on held-out data and interpretability is not needed. Before committing to this method, check the independence assumption in practice: inspect the correlations among features within each class, and treat strong correlations as a warning sign. Then compare, on the same held-out split and with the same preprocessing, a single Naive Bayes model, the ensemble, and a discriminative baseline such as logistic regression. Keep the ensemble only if it outperforms the single model on that held-out comparison.

Limitations and considerations

  • Bias from the conditional independence assumption is not reduced by ensembling; if the assumption is fundamentally wrong, adding more Naive Bayes members does not correct it.
  • The ensemble is less transparent than a single Naive Bayes model, because the final decision is an aggregate of several sets of class-conditional estimates.
  • For continuous, correlated features, tree-based ensembles such as random forests or gradient boosting are generally stronger alternatives that model feature interactions directly.
  • Members trained on overlapping resamples are correlated, so the variance reduction is smaller than the number of members would suggest.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Keeps the probabilistic form of Naive Bayes, so the combined output is a score per class that can be compared across observations.
  • Training remains cheap, since each member has closed-form parameter estimates from counts or means and variances.
  • Bagging-style resampling is intended to target the variance of the estimated class-conditional terms, which can be unstable when some feature-class counts are sparse.
  • Scales to high-dimensional bag-of-words representations without feature engineering, as the base Naive Bayes does.

Applications

  • Spam and phishing email detection on bag-of-words representations.
  • Sentiment analysis on short texts, where Multinomial NB is a common baseline.
  • Document categorisation in high-dimensional text corpora.

How it works

How it works

1

A Naive Bayes variant is chosen as the base learner: Gaussian NB for continuous features, Multinomial NB for count data such as word counts, or Bernoulli NB for binary indicators. All members use the same variant, but each is fitted to a different view of the data.

2

Diversity between members is created by bootstrap sampling of training rows (bagging), by random selection of feature subsets, by partitioning the features into groups, or by reweighting samples as in boosting. Without some such variation, the members would be nearly identical and combining them would give little benefit.

3

Each member estimates the class prior P(y) and the class-conditional terms P(x_i | y) from its own data view. For a new observation, the member's score P(y) times the product of P(x_i | y) is proportional to the posterior P(y | x); the normalising constant is omitted, which does not change the ranking of classes within a member.

Formula
P(y|x) = \prod_{i=1}^{n} P(x_i|y) \cdot P(y)
4

The members' log-scores are combined as a weighted sum over members, and the predicted class is the one with the largest combined score. The weights can be set equally or chosen from out-of-bag or validation accuracy. Majority voting and probability averaging are alternative combination rules that do not follow this exact formula.

Formula
\hat{y} = \arg\max_y \sum_{k=1}^{K} w_k \log P_k(y|x)

Common pitfalls

  • Assuming that more members always help; gains may level off after a moderate number of members. The 10 to 50 member range used on this page is only a starting point to tune against validation error, not a threshold.
  • Choosing the wrong Naive Bayes variant for the feature type (Gaussian, Multinomial or Bernoulli), which leads to poorly calibrated member scores.
  • Evaluating on the training data or on bootstrap samples that overlap the test set, and concluding the ensemble beats a tuned single model.
  • Omitting Laplace (additive) smoothing in members trained on sparse text, which can produce zero probabilities for unseen feature-class pairs.
  • Applying the ensemble to strongly correlated continuous features without decorrelating or transforming them first.

Frequently asked questions

Does ensembling fix the Naive Bayes independence assumption?

No. Ensembling is intended to reduce the variance of the estimates across members, but it cannot remove the bias introduced by assuming conditional feature independence. If that assumption is severely violated, consider models that represent feature interactions directly, such as logistic regression or gradient boosting.

How many Naive Bayes members should the ensemble have?

There is no fixed answer. Starting from the 10 to 50 range used on this page as a working guide, tune the number of members against out-of-bag or cross-validation error and stop when adding members brings little further change. More members add inference time and may yield only small gains.

Bagging vs. boosting for NB ensembles: which is better?

The sources for this entry do not settle which approach performs better for Naive Bayes. Bagging (bootstrap sampling) is straightforward to implement, and boosting may help when the base model makes systematic errors on certain sub-regions, but it can also amplify the base model's bias. Compare both with cross-validation on your own data.

Which Naive Bayes variant should I use as the base model?

Choose Gaussian NB for continuous numeric features, Multinomial NB for word counts or term-frequency features, and Bernoulli NB for binary occurrence features. The variant must match the data type, since mixing incompatible variants inside the ensemble typically degrades performance.

When is a plain Naive Bayes better than the ensemble version?

When the training data are very small or when a single, directly inspectable probability model is the priority. In these cases the ensemble adds complexity and may not reduce variance in a meaningful way.

Related methods

Sources

  1. Dietterich, T. G. (2000). Ensemble Methods in Machine Learning. In J. Kittler & F. Roli (Eds.), Multiple Classifier Systems (MCS 2000), Lecture Notes in Computer Science, vol. 1857, pp. 1–15. Springer.

    Open DOI reference
  2. Lowd, D. & Domingos, P. (2005). Naive Bayes Models for Probability Estimation. In Proceedings of the 22nd International Conference on Machine Learning (ICML 2005), pp. 529–536. ACM.

    Open DOI reference