Skip to content
CoreSource checked

Naive Bayes

Classifies examples using feature probabilities and a simplifying independence assumption.

Quick Facts

Compact metadata for implementation and discovery.

Category
Machine Learning
Difficulty
Beginner
Family
Probabilistic Classification
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
2
Code example
Not ready
Visualization
Ready

Overview

Naive Bayes estimates how likely each class is given the observed features, assuming features contribute independently within a class.

Core Concepts

learned parametersclass decision boundarylabeled examplesprobabilistic classificationmodel fittraining examplesprediction rule

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(nd)

Average

O(nd)

Worst

O(nd)

Space

O(cd)

When to Use

  • Use Naive Bayes when you need to estimate class and feature probabilities.
  • Use it when the input assumptions match the method's model.
  • Use it when you have data that matches the model's assumptions and a measurable target or structure.
  • Use it when the method's tradeoffs fit the workload.

When Not to Use

  • Avoid it when there is not enough representative data to train or evaluate the model.
  • Avoid it when the required output is not class probabilities.

What It Does

  • Estimates class and feature probabilities
  • Chooses the class with the highest posterior score

Use Cases

  • Text classification
  • Spam filtering
  • Simple probabilistic baselines

Inputs

  • Feature values
  • Class labels for training

Outputs

  • Class probabilities
  • Predicted label

Key Formulas (1)

Naive Bayes score

score(class) = P(class) · product(P(featurei | class))
score(class) = P(class) * product(P(feature_i | class))

Scores each class by multiplying the prior and feature likelihoods.

Pseudocode

  1. 1.Count class frequencies
  2. 2.Estimate feature likelihoods per class
  3. 3.For a new example, score each class
  4. 4.Multiply or add log probabilities
  5. 5.Return the highest-scoring class

Canonical Example

Input
examples = [[size, price], ...], target = label or value
Output
model predictions for new examples
Explanation
Naive Bayes: The algorithm learns a pattern from examples and applies it to unseen data.

Implementation Notes

  • Keep the input contract explicit: Feature values; Class labels for training.
  • Split data for evaluation and track preprocessing steps so predictions use the same feature format.
  • Treat examples as educational sketches; production models need validation, monitoring, and domain checks.

Common Pitfalls

  • The independence assumption is often false, but the model can still work well.
  • Evaluating only on training data and mistaking memorization for useful performance.
  • Handle empty, invalid, and boundary inputs before trusting class probabilities.
  • Data leakage, unscaled features, and validation on training data can make results look better than they are.

Interactive Mechanism Walkthrough

Iterative Convergence & State Trajectory

Show feature evidence adding to class probability scores.

Naive Bayes mechanism walkthrough step 1 of 5x₀x₁x₂x*
Step 1 of 5: Count class frequencies
class-probabilities

Notes

Naive Bayes operates in O(nd) time and O(cd) space within the Probabilistic Classification family. Key governing relation: score(class) = P(class) * product(P(feature_i | class)). Often compared with Logistic Regression and Support Vector Machine.

Sources (1)

What each reference supports for this entry.

The Elements of Statistical Learning

Book

Statistical learning reference for the model family and tradeoffs of Naive Bayes.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Alternative toLogistic Regression

Naive Bayes and logistic regression are simple probabilistic classifiers with different independence assumptions.

Tags

Machine LearningClassificationSupervised Learning