Notes

Categorical Naive Bayes

Some datasets aren’t made of numbers like “age” or “income”—they’re made of choices: browser type, country, plan tier, or symptom category. Categorical Naive Bayes is the Naive Bayes flavor built specifically for that kind of input.

What it is and what it assumes

Categorical Naive Bayes is a probabilistic classifier that applies Bayes’ theorem while treating each feature as a categorical variable (a finite set of labels). For each class (like “spam” vs “not spam”), it learns a probability table for every feature: P(feature=value | class). At prediction time, it multiplies those per-feature probabilities together (the “naive” part is the conditional independence assumption: features are independent given the class) and combines them with the class prior P(class) to pick the most likely class.

How it learns from data (and why smoothing matters)

Training is basically counting: for each class, count how often each category value appears in each feature, then normalize into probabilities. A key practical detail is additive (Laplace) smoothing, which prevents zero probabilities when a category value wasn’t seen in training for a class (a single zero would wipe out the whole product). In scikit-learn, this is implemented as sklearn.naive_bayes.CategoricalNB with an alpha smoothing parameter.

Where you’ll use it

  • Customer churn: plan type, contract category, support channel → churn vs stay.
  • Fraud detection: merchant category, device type, country → fraud vs legitimate.
  • Medical triage: symptom categories, risk group labels → likely condition class.

It matters because it lets you model categorical predictors directly, without forcing them into a Gaussian assumption (wrong for labels) or a bag-of-words count model (wrong for general categories). When the independence assumption is “good enough,” it’s fast, data-efficient, and surprisingly competitive.

Categorical Naive Bayes is a Naive Bayes classifier designed for features that take one of a finite set of discrete categories, modeling each feature’s class-conditional probabilities with a categorical distribution (typically estimated from counts with smoothing). It matters because it provides a fast, interpretable baseline for classification when inputs are nominal (e.g., color, country, product type), where Gaussian or multinomial assumptions are inappropriate.

Think of sorting mail using a checklist: “Does it say ‘sale’?”, “Is the sender a known store?”, “Is there an unsubscribe link?” Each clue is a category, not a number. Categorical Naive Bayes is an AI method that learns from past labeled examples (like “spam” vs “not spam”) and then guesses the most likely label for a new item based on those category-style clues.

It’s especially handy when your inputs are things like colors, brands, yes/no flags, or word types. It’s called “naive” because it treats each clue as if it’s independent, which isn’t always true, but often works surprisingly well.