Skip to content
mlmentorship

Naive Bayes

A trivially simple generative classifier that assumes features are conditionally independent given the class. Fast, parameter-light, surprisingly hard to beat on text.

Published · 5 min read ·Core ·Foundation

Summary

Naive Bayes models , assuming features are conditionally independent given the class . Trained by counting (closed-form MLE for each conditional).

Naive Bayes is the cheapest possible probabilistic classifier. Closed-form MLE, training, prediction, no hyperparameter tuning. Despite the obviously wrong independence assumption, it works remarkably well as a baseline on:

  • Text classification (spam filtering, topic categorization, sentiment): bag-of-words features.
  • Tiny-data classification where logistic regression overfits.
  • Initial baselines that should be beaten before claiming victory with a fancier model.

It is also conceptually important. The canonical example of a generative classifier (model ) versus the discriminative logistic regression (model directly).

The model

By Bayes’ rule:

The “naive” assumption: . Then for prediction:

Sum logs to avoid underflow.

Variants

VariantUse case
MultinomialMultinomial over token countsText (bag-of-words)
BernoulliBernoulli (binary) per featureText (presence/absence)
GaussianContinuous features
CategoricalCategorical (multinoulli)Discrete features

Training

Just count.

For multinomial NB on text:

  • .
  • (with Laplace / additive smoothing , typically 1.0; = vocabulary size).

Without smoothing, any unseen word in a class gives and , breaking inference.

Why the independence assumption isn’t fatal

Even though words are clearly correlated, naive Bayes can still rank classes correctly. The independence assumption gives biased probability estimates (overconfident. Predicted probabilities tend to be near 0 or 1) but the argmax is often right.

For pure classification accuracy, NB is competitive. For calibrated probabilities, prefer logistic regression with proper regularization.

Learning objective

Multiplying evidence ratios requires conditional independence within each class

Evidence ratios multiply only under the declared independence modelPrior odds 1:4 become 1:1 after likelihood ratio 2 and another ratio 2. Correlated evidence cannot be multiplied as independent evidence without justification.Independent evidence changes relativeweightPrior odds 1:41:4 becomes 20%After one likelihood ratio of two2:4 becomes 33.33%After a second independent ratio oftwo4:4 becomes 50%Correlated evidence needs a differentjoint model.
Derivation

Model score: count every token separately

For two equally likely classes, suppose a text model learned these illustrative likelihood ratios for a document containing “free prize.”

Prior odds1 : 1
“free”× 8
“prize”× 7
NB odds56 : 1 spam

1 × 8 × 7 = 56 → choose spam

Reality check: evidence can overlap

“Free” and “prize” may come from the same promotional phrase, so their occurrences can remain correlated even after the class is known.

NB assumestwo conditionally independent contributions
Text may containone underlying signal expressed twice
Class decisionspam can still win
Probability56 : 1 can overstate certainty

use the argmax; distrust uncalibrated probability

Read it this way: multiply down the left ledger first: naive Bayes gives each observed token its own likelihood-ratio contribution, so the class score can separate sharply. Then read the right panel: if correlated tokens repeat one underlying signal, multiplying them as independent evidence exaggerates the odds. The winning class can remain correct even when the reported probability is overconfident. The numbers are an original illustrative calculation, checked against the Introduction to Information Retrieval treatment of multinomial naive Bayes and scikit-learn's official model guidance.
Check: What independence assumption permits multiplying 8 by 7? Why do those numbers alone not identify the correct joint odds?
Read it this way: Prior odds 1:4 become 1:1 after likelihood ratio 2 and another ratio 2. Correlated evidence cannot be multiplied as independent evidence without justification.
What assumption permits the second likelihood ratio to multiply the first?

Generative vs. discriminative

Naive Bayes models the joint . Logistic regression models directly. Asymptotic results (Ng & Jordan, 2002):

  • For small , NB usually wins (less variance from the strong assumption).
  • For large , logistic catches up and surpasses NB (the assumption hurts at large scale).

Where it shows up in 2026

  • Spam filters in low-resource embedded systems.
  • Quick text baselines before training a transformer.
  • Document filtering in retrieval pipelines (cheap pre-filter).

For most modern NLP, neural classifiers dominate. NB persists in resource-constrained settings and as a reliable benchmark.

Common pitfalls

  • Forgetting to smooth. Without Laplace smoothing, any test document with a vocabulary token never seen in a class gets that class’s posterior set to 0.
  • Using NB on highly correlated features. Probabilities become very poorly calibrated; predicted class can still be okay but never trust the probability.
  • Mixing variants. Multinomial NB on continuous features is wrong; use Gaussian NB (or discretize first).
  • Comparing NB on raw counts vs. tfidf vs. binarized. Different preprocessing changes the model class; compare apples to apples.