What is a naive Bayes classifier?
Naive Bayes is a family of probabilistic classifiers that apply Bayes' rule with one simplifying assumption: given the class, every feature is independent of the others. Under that assumption, the likelihood of a whole input is a product of one-feature likelihoods, each easy to estimate from counts or from a per-class mean and variance. The prediction is the class with the highest posterior probability.
Naive Bayes trains in a single pass and needs little data, so it is a standard baseline for text classification tasks such as spam filtering, sentiment analysis, and topic labeling. Variants match the feature type: Gaussian naive Bayes for continuous values, multinomial naive Bayes for word counts, and Bernoulli naive Bayes for word presence or absence.
Key ideas
- Naive Bayes picks the class with the highest posterior, P(class | x) ∝ P(x | class) · P(class).
- It assumes features are independent given the class, so the likelihood is a product of one-feature terms.
- Training only estimates per-class statistics such as means, variances, or word frequencies.
- Implementations add log-probabilities instead of multiplying probabilities, to avoid underflow.
- Changing the prior shifts the decision boundary without changing its shape.
- Its probabilities are often overconfident, even when its class predictions are accurate.
Common questions
Why is naive Bayes called naive?
It assumes every feature is independent of every other feature once the class is known. That is rarely true: in an email, "free" and "prize" tend to appear together. The assumption is a deliberate simplification that makes the model fast and data-efficient.
What is Laplace smoothing in naive Bayes?
If a word never appears in the spam training set, its estimated P(word | spam) is zero, and a single occurrence in a new email would force the spam probability to zero. Laplace (add-one) smoothing adds 1 to every count before dividing, so every word keeps a small nonzero probability. The added amount, often called alpha, can be tuned.
Is naive Bayes generative or discriminative?
Generative. It models how each class produces features, P(x | class), along with the class prior, and classifies with Bayes' rule. Logistic regression is its discriminative counterpart. Ng and Jordan (2001) found that naive Bayes approaches its best error with fewer training examples, while logistic regression usually reaches a lower error once data is plentiful.
Are naive Bayes probabilities reliable?
Usually not as probabilities. Correlated features are counted more than once, which pushes posteriors toward 0 or 1. When calibrated probabilities matter, Platt scaling or isotonic regression can be fitted on held-out data to correct them.
Related explainers
- Bayes' Theorem — Updating beliefs with evidence
- Probability & Distributions — Spam, densities, and the math of uncertainty
- Text Classification & Sentiment — Teach a model to assign labels to text — from spam detection to sentiment analysis
- Bag of Words — Turn text into numbers — count word occurrences to create the simplest document representation in NLP
- MLE & MAP Estimation — Maximum likelihood and maximum a posteriori — why training works
- Class Imbalance & Resampling — SMOTE, class weights, and metrics beyond accuracy
References
- Domingos & Pazzani (1997), "On the Optimality of the Simple Bayesian Classifier under Zero-One Loss", Machine Learning
- Jurafsky & Martin, "Speech and Language Processing" (3rd ed. draft), chapter on Naive Bayes and Sentiment Classification
- James, Witten, Hastie & Tibshirani, "An Introduction to Statistical Learning", chapter 4: Classification
Last updated