Semi-supervised Naive Bayes

Machine Learning
Introduced by
Nigam, K.; McCallum, A. K.; Thrun, S.; Mitchell, T.
Year
2000
Type
Semi-supervised generative classifier
Family
Machine learning

What does it do?

Semi-supervised Naive Bayes extends the classic Naive Bayes generative model so that it can also use unlabeled data alongside a small labeled set.

Using Expectation-Maximization, it iteratively infers soft class assignments for the unlabeled examples and re-estimates the class and feature parameters. When labeled examples are scarce, this can yield a better classifier than labeled data alone would support.

The intuition behind the method

Classic Naive Bayes estimates class priors and feature likelihoods from labeled examples only. When labels are expensive but raw data is plentiful, the information carried by the unlabeled examples goes unused. Semi-supervised Naive Bayes treats the unknown labels of those examples as hidden variables. It alternates between estimating them under the current model (E-step) and re-estimating the model using those estimates (M-step). Over successive iterations the parameters can move toward a better fit than the labeled examples alone support, provided the unlabeled data come from the same task as the labeled data.

History

Nigam, McCallum, Thrun, and Mitchell (2000) studied the use of EM for text classification with both labeled and unlabeled documents, the setting in which the method described here is applied. Chapelle, Schölkopf, and Zien (2006) provide a broader survey of semi-supervised learning, including generative models.

When to use it

Consider this method when labeled examples are scarce relative to the amount of unlabeled data drawn from the same task and distribution. No fixed number of labeled examples marks when the method applies; judge its benefit against a labeled-only baseline on held-out data. This pattern is common in text classification, spam filtering and biomedical document categorization. The method fits best when features are conditionally independent given the class, or approximately so, which makes bag-of-words and count-based representations natural inputs. Avoid it when the unlabeled data come from a different distribution than the labeled set (covariate shift), because the EM updates can then reduce accuracy; if it is used anyway, λ must be tuned on labeled data. Also avoid it when the conditional independence assumption is severely violated and a discriminative model is expected to perform better regardless of label scarcity.

Limitations and considerations

  • Inherits the Naive Bayes conditional-independence assumption. When features are strongly correlated given the class, the likelihood estimates and the soft labels derived from them are distorted.
  • EM converges to a local optimum that depends on the starting point. Here the starting point is the labeled-only model, so the result should be checked against alternative initializations.
  • Unlabeled data from a shifted distribution can degrade accuracy (negative transfer) unless their contribution is down-weighted.
  • With strongly correlated features, discriminative semi-supervised methods such as the transductive SVM or label propagation may outperform it, because they do not depend on the same independence assumption.

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

Strengths

  • Uses unlabeled data that a purely supervised Naive Bayes model would discard, which can reduce the number of labeled examples needed for a given accuracy.
  • Each EM iteration passes over the data once, so the cost grows linearly with the size of the data, which suits large text corpora.
  • Each EM iteration does not decrease the objective it maximizes, and the procedure converges to a stationary point of that objective, typically a local optimum. With equal weighting this objective is the likelihood of the labeled and unlabeled data; with a λ-weighted unlabeled term, the monotone improvement applies to that weighted criterion rather than to the unweighted likelihood.
  • Provides class posteriors, so predictions can be ranked and thresholded; their calibration should still be checked on held-out data.
  • Simple to implement and extend, and λ gives a direct control over how much the unlabeled data influence the fit.

Applications

  • Text and document classification with limited labeled training data.
  • Spam and phishing detection, where labeled spam is scarce but unlabeled email is abundant.
  • Biomedical literature categorization, such as PubMed article triage, with small expert-labeled subsets.
  • Web-page topic classification using a small hand-labeled seed set and a large crawled corpus.
  • Email or ticket routing where only some historical tickets have confirmed category labels.

How it works

How it works

1

Train an ordinary Naive Bayes model on the labeled examples only, using Laplace smoothing to handle feature values that do not occur in that set. This yields initial estimates of the class priors P(y) and the feature likelihoods P(x_j | y). The model is a starting point for the EM loop, not the final classifier.

2

Apply the current model to every unlabeled example and compute its posterior class probabilities, P(y | x, θ). Each unlabeled instance is assigned fractionally to every class in proportion to these posteriors. The resulting fractional counts are kept alongside the hard counts from the labeled data.

Formula
P(y_i | x_i, \theta) = \frac{P(y_i|\theta)\,P(x_i|y_i,\theta)}{\sum_c P(c|\theta)\,P(x_i|c,\theta)}
3

Re-estimate the class priors and feature likelihoods by combining the hard counts from the labeled examples with the fractional counts from the E-step. Each unlabeled example contributes to each class in proportion to its inferred weight, so unlabeled data can shift the parameters when their inferred class structure is informative.

4

Repeat the E-step and M-step until the log-likelihood of the labeled and unlabeled data converges or a maximum number of iterations is reached. The weight λ scales the contribution of the unlabeled data. Reducing λ limits their influence when they may come from a different distribution than the labeled set.

5

Once converged, classify new examples with the standard Naive Bayes rule, assigning the class with the highest posterior under the learned parameters. Inference is the same as for ordinary Naive Bayes and is closed-form, so it remains fast on large document collections. The formulas assume discrete features such as word counts, with per-class feature likelihoods P(x_j | c), which is the usual setting for text. For continuous features, the likelihood is replaced by a parametric form such as a Gaussian, and the EM loop keeps the same structure.

Formula
\hat{y} = \arg\max_c\, P(c)\prod_j P(x_j|c)

Common pitfalls

  • Pooling labeled and unlabeled examples drawn from different tasks or domains. Verify that both come from the same task before combining them.
  • Leaving λ at its equal-weight setting without checking whether the unlabeled data are representative. λ should be selected on the labeled data over a grid of candidate values.
  • Evaluating on the labeled examples used for training, or without a held-out test set, which inflates the apparent accuracy.
  • Treating EM convergence as evidence of a better classifier. Compare against a labeled-only Naive Bayes baseline and a simple self-training baseline.
  • Omitting Laplace smoothing. Feature values unseen in the labeled data then receive zero likelihoods, which can break the posterior computation in the E-step.

Frequently asked questions

How many labeled examples do I need to get a good starting model?

There is no fixed number of labeled examples that marks when the method applies. It helps most when labels are scarce relative to the available data. A labeled-only Naive Bayes model with Laplace smoothing is the baseline to beat, and more labeled examples generally help both approaches.

What is the lambda parameter and how do I tune it?

Lambda controls how much weight the unlabeled examples receive relative to labeled ones during the M-step (lambda=1 treats them equally; lambda=0 ignores them). Tune it via cross-validation on the labeled set, starting with values in {0.1, 0.3, 0.5, 1.0}. Reduce lambda when you suspect distribution mismatch.

Will EM always improve on a labeled-only Naive Bayes?

No. If the unlabeled data come from a different distribution, EM can move the parameters in the wrong direction and increase error. Always benchmark against the labeled-only baseline before deploying the semi-supervised model.

How does this differ from self-training with Naive Bayes?

Self-training assigns hard labels to unlabeled examples above a confidence threshold and then retrains. EM assigns soft, fractional labels to all unlabeled examples at every iteration, which is a probabilistic alternative to that step. It can also reduce the risk that early confident mistakes are amplified, which can happen with hard self-training.

Is this suitable for non-text tabular data?

Yes. For continuous features, replace the multinomial likelihood with Gaussian (or other parametric) likelihoods per class. The EM loop structure is identical; only the M-step parameter formulas change.

Related methods

Sources

  1. Nigam, K., McCallum, A. K., Thrun, S., & Mitchell, T. (2000). Text Classification from Labeled and Unlabeled Documents using EM. Machine Learning, 39(2–3), 103–134.

    Open DOI reference
  2. Chapelle, O., Scholkopf, B., & Zien, A. (Eds.). (2006). Semi-Supervised Learning. MIT Press.

    ISBN: 978-0-262-03358-9