Machine LearningClassification Models & Kernels

What is Gaussian Naive Bayes?

Gaussian Naive Bayes (GaussianNB) is a probabilistic classifier designed for continuous numerical features. For each class, it assumes each feature follows a Gaussian (normal) distribution, described by a mean and variance. Like other Naive Bayes models, it assumes features are conditionally independent given the class.

How does it work?

  1. Calculate class priors: estimate how often each class occurs in the training set.
  2. Learn Gaussian parameters: calculate the mean and variance of each numerical feature separately for each class.
  3. Evaluate a new observation: calculate its Gaussian likelihood under each class.
  4. Choose the class with the largest prior-weighted product of feature likelihoods (usually computed using log-scores for numerical stability).

Gaussian likelihood formula

p(x | class) = 1 / sqrt(2*pi*variance)
             * exp(-(x - mean)^2 / (2*variance))

Here, mean and variance are estimated from the training observations belonging to that class. The formula gives a probability density, not a probability of an exact continuous value.

Numerical example: predict a sensor condition

Suppose a sensor measurement is used to identify two conditions:

  • Normal: measurements 1, 2, 3.
  • Alert: measurements 7, 8, 9.

Both classes have three observations, so the estimated class priors are 0.5 each.

  • Normal: mean = (1+2+3)/3 = 2; variance = ((1-2)^2 + (2-2)^2 + (3-2)^2)/3 = 2/3.
  • Alert: mean = 8; variance = 2/3.

For a new reading 2.5, its Gaussian density is far higher under the Normal class (centered near 2) than the Alert class (centered near 8). With equal priors, Gaussian Naive Bayes predicts Normal.

Python example

PYTHON
from sklearn.naive_bayes import GaussianNB X = [[1], [2], [3], [7], [8], [9]] y = ['Normal'] * 3 + ['Alert'] * 3 model = GaussianNB() model.fit(X, y) print(model.predict([[2.5]])) # ['Normal'] print(model.theta_) # Class-wise feature means print(model.var_) # Class-wise feature variances

When should you use it?

  • Useful for continuous measurements such as temperature, duration, or physical sensor readings when the per-class distributions are reasonably Gaussian.
  • Often provides a fast, simple baseline with limited training data.
  • Less suitable when feature distributions are strongly non-Gaussian or features remain highly correlated within classes.

Practical detail: scikit-learn's GaussianNB uses var_smoothing to add a small positive quantity to feature variances for numerical stability, particularly when a feature has little or no variance.

In short: Gaussian Naive Bayes learns a mean and variance for every feature in every class, then uses Gaussian likelihoods plus class priors to classify new numerical observations.

References

#Gaussian Naive Bayes explained#GaussianNB mean variance example#Gaussian Naive Bayes continuous features#GaussianNB scikit learn#machine-learning#classification#naive-bayes#gaussian-naive-bayes#continuous-features

Learning Sequence

Machine Learning Curriculum

69% Completed
Up NextMachine Learning

What is Multinomial Naive Bayes?

Explore Related Questions

Deepen your understanding across related Machine Learning topics.

Machinoai Logo
Machinoai

Your edge in the AI era. Deep dives into machine learning concepts, paper explainers, verified industry jobs, and developer tools.

© 2026 Machinoai. All rights reserved.