- Introduced by
- Mitchell, T. M. (textbook treatment)
- Year
- 1997
- Type
- Probabilistic classifier (Bayes' theorem with conditional independence)
What does it do?
Naive Bayes is a fast probabilistic classifier that applies Bayes' theorem under the assumption that the features are conditionally independent given the class.
Tom Mitchell's 1997 textbook Machine Learning gives a standard treatment of the method, and it is the reference cited here. Despite this simplifying ('naive') assumption, it is quick to train and can perform well in practice.
The intuition behind the method
Rather than modelling how features interact, Naive Bayes asks a simpler question: within each class, how likely is each feature value on its own? It multiplies these per-feature likelihoods together with the class's base rate and selects the class with the highest resulting score. Ignoring interactions keeps estimation simple and training fast. Because classes are compared with one another, the ranking of classes can remain useful even when the independence assumption is violated, although the absolute probabilities may not be.
History
The method applies Bayes' theorem, a long-established result in probability, and has been widely used in applied classification, notably for text tasks such as spam filtering. Bayesian classifiers have been applied to junk email filtering, author identification, topic categorisation and intrusion or anomaly detection in computer networks (syncfusion-predictive-analytics library copy). Tom Mitchell's 1997 textbook Machine Learning gives a standard treatment of Bayes classifiers and is the reference cited for the formulation used on this page.
When to use it
Choose Naive Bayes for fast classification when the features are categorical, binary, continuous, or count-based (such as text term frequencies), and when every class has enough labelled observations to estimate its prior and likelihoods. Match the variant to the feature type as described in the estimate section. It is particularly useful as a cheap baseline before trying more complex models. Its conditional-independence assumption is strong, and each variant adds its own likelihood assumption, such as within-class normality for the Gaussian variant. Avoid it when features are strongly correlated and you need reliable probabilities, or when interactions between features drive the class; logistic regression, tree-based methods, or support vector machines are usually more suitable in those cases.
Limitations and considerations
- The conditional-independence assumption is usually violated; correlated features are counted as independent evidence, which inflates the combined score and can make posterior probabilities overconfident.
- Class priors enter the product directly, so a heavily imbalanced training set biases predictions toward the majority class unless the priors are adjusted or the data resampled.
- Gaussian Naive Bayes relies on within-class normality; skewed or multimodal continuous features can produce poor likelihood estimates.
- A feature value never observed with a class gives a zero likelihood that zeroes the whole product for that class, so smoothing is needed; without it, estimates from small samples are unstable.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Training needs only class counts and per-feature likelihood estimates, so its cost grows with the number of features and classes rather than with feature interactions.
- Because interactions are not modelled, the number of parameters stays small compared with models that estimate joint distributions, which is one reason it needs comparatively little data.
- Scales to high-dimensional sparse data such as text, where each term's likelihood is estimated separately.
- Different variants accommodate categorical, binary, continuous, and count features, so the model can be matched to the data type.
- Useful as a low-cost baseline for judging whether more complex models add value.
Applications
- Spam filtering and document categorisation based on word-count features.
- A quick baseline classifier before fitting more complex models.
- Classification with categorical, binary, continuous, or count features.
- High-dimensional problems where training speed is a constraint.
- Author identification and intrusion or anomaly detection in computer networks.
How it works
How it works
By Bayes' theorem, the probability of a class given the observed features is proportional to the class's prior probability times the likelihood of those features under that class. The 'naive' step is to assume the features are conditionally independent given the class, so the joint likelihood factorises into a product of per-feature likelihoods. Viewed as a Bayesian network, this means the class node has no parents and is the single parent of every feature node, which is the structure that encodes the independence assumption (Kelleher, Mac Namee and D'Arcy, p. 352). This assumption rarely holds exactly. When features are correlated, the product counts shared evidence more than once.
Formula
P(y \mid x_1,\dots,x_p) \propto P(y)\prod_{i=1}^{p} P(x_i \mid y)Training estimates the class priors and the per-feature likelihoods from the labelled data. Each class prior is that class's share of the training observations. The form of the likelihood depends on the variant. Gaussian Naive Bayes models each continuous feature as normally distributed within each class, using the class-wise mean and variance. Multinomial Naive Bayes is designed for count data such as term frequencies in text and does not accept negative values; each per-feature likelihood is the share of that feature's counts within the class, usually with additive (Laplace) smoothing so that unseen feature values do not produce zero likelihoods. Bernoulli Naive Bayes is intended for binary features that record the presence or absence of a feature, and estimates the probability that each feature is present within each class. Categorical Naive Bayes is intended for discrete features with several categories, and estimates a distribution over the categories of each feature within each class. Every per-feature estimate uses only the rows of its own class, so a class with few observations has unreliable priors and likelihoods, even when the total sample is large. No fixed minimum sample size applies; the number of observations in each class matters most.
For a new observation, the model multiplies the class prior by the per-feature likelihoods for each candidate class and assigns the class with the largest result. Classes are compared directly, so an imbalanced prior gives the majority class an advantage. Adjusting the priors or resampling the training data changes which class wins, and this should be considered before the predictions are relied on.
Formula
\hat{y} = \arg\max_{y} \; P(y)\prod_{i=1}^{p} P(x_i \mid y)Common pitfalls
- Reading the output probabilities as well-calibrated risks; they are better treated mainly as a ranking of classes.
- Ignoring class imbalance and leaving the priors at their training-set frequencies.
- Passing negative values into Multinomial Naive Bayes, which it does not accept.
- Applying Gaussian Naive Bayes to clearly non-normal continuous features without checking the distribution within each class.
- Fitting the model when some classes have very few observations, even if the total sample is large.
Frequently asked questions
Why is it called 'naive'?
Because it assumes the features are conditionally independent given the class, meaning that within a class, knowing one feature tells you nothing about another. This is rarely literally true, but the simplification makes the model straightforward to estimate and fast to run, and the classifier often still ranks classes accurately.
Which variant should I use?
Gaussian Naive Bayes is for continuous features assumed to be normally distributed within each class. Multinomial Naive Bayes suits count or term-frequency data, as in text classification, and does not accept negative values. Bernoulli Naive Bayes suits binary presence/absence features, and Categorical Naive Bayes suits discrete features with several categories. Match the variant to your feature type.
Can I trust the predicted probabilities?
Use the predicted class with care, as a ranking. Because the independence assumption is usually violated, the raw probabilities tend to be pushed toward 0 or 1 and are often poorly calibrated, even when the chosen class is correct. Before using them as risk estimates, check calibration on held-out data, for example with a calibration curve or the Brier score. If probabilities are needed, consider a calibration method such as Platt scaling or isotonic regression.
How much data does it need?
There is no fixed minimum sample size. Naive Bayes needs relatively little data, but each class needs enough observations for its prior and per-feature likelihoods to be estimated reliably. Check the count in every class; if some classes are very small, the estimates will be unstable.
Related methods
Sources
Mitchell, T. M. (1997). Machine Learning. McGraw-Hill.
ISBN: 978-0070428072Kelleher, J. D., Mac Namee, B., & D'Arcy, A. (library copy catalogued as '[John_D._Kelleher_,_Brian_Mac_Namee_,_Aoife_D'Arcy(z-lib.org)'), p. 352
syncfusion-predictive-analytics (library copy), p. [not recorded in library]