Supervised LearningBinary / Multi-ClassClassification

Gaussian Naive Bayes

Primary task · Classification

Gaussian Naive Bayes is a supervised learning method in the binary / multi-class family. This page summarizes its mechanism, practical uses, important trade-offs, and a browser-based concept explorer.

← Directory
Visual intuition

From data to learned behaviour

Gaussian Naive Bayes converts patterns in observed data into a reusable prediction or representation rule. The most useful way to understand it is to watch what internal structure changes during training and how that learned structure changes outputs.

Infographic
1Data2Initial state3Optimise4Validate5InferenceTraining transforms evidence into a reusable model state
Conceptual simulation

Watch the learning mechanism form

The structure below is synchronized with the same training state used by the prediction simulation.

Mechanism view
Training control centre

Control both simulations together

Reset regenerates the synthetic data and model state. Train animates to completion. Pause freezes the animation. Train Step advances one learning stage.

Step 0 / 20
Model simulation

Inspect the learned prediction / representation

Synthetic data are generated locally in your browser.

Model description

Understand Gaussian Naive Bayes after watching it learn

This section connects the animation to the actual statistical or computational idea behind the model.

Deep description

Gaussian Naive Bayes Gaussian Naive Bayes is a supervised learning method in the binary / multi-class family. This page summarizes its mechanism, practical uses, important trade-offs, and a browser-based concept explorer.

What is learned. During training, the algorithm builds or adjusts the parameters and internal representation used by Gaussian Naive Bayes. The core learning mechanism is: Applies Bayes' Theorem assuming continuous features follow a Gaussian normal distribution and features are mutually independent given the class.

How training becomes inference. Prepare data → initialise the model state → evaluate the current objective → update parameters or structure → validate progress → use the final state for inference. Once training stops, the fitted state is reused on unseen inputs rather than being reconstructed from scratch. The resulting output is: Class probabilities or class labels, depending on the decision threshold and API used.

Why practitioners use it. Extremely fast to train and predict; requires very little training data to estimate parameters. Typical fits include Real-time sentiment analysis, spam filtering, initial baseline classification on small datasets.

What to verify before trusting it. Strong 'naive' conditional independence assumption rarely holds in real-world correlated data. The visual simulation is intentionally simplified, so real use should still validate preprocessing, data independence, hyperparameters, uncertainty and task-appropriate metrics.

Internal statethe parameters and internal representation used by Gaussian Naive Bayes
Typical outputClass probabilities or class labels, depending on the decision threshold and API used.
Good fitReal-time sentiment analysis, spam filtering, initial baseline classification on small datasets.
Main cautionStrong 'naive' conditional independence assumption rarely holds in real-world correlated data.
1Training data→
2Learning objective→
3Internal model state→
4Prediction / representation→
5Evaluation
Intuition

What the model is trying to learn

Gaussian Naive Bayes converts patterns in observed data into a reusable prediction or representation rule. The most useful way to understand it is to watch what internal structure changes during training and how that learned structure changes outputs.

Mathematical lens

Core logic

Applies Bayes' Theorem assuming continuous features follow a Gaussian normal distribution and features are mutually independent given the class. The mathematical objective determines which model states are considered better, while regularisation and validation constrain how much complexity should be trusted.

Training sequence

How learning progresses

Prepare data → initialise the model state → evaluate the current objective → update parameters or structure → validate progress → use the final state for inference.

Original mechanism

Taxonomy description

Applies Bayes' Theorem assuming continuous features follow a Gaussian normal distribution and features are mutually independent given the class.

Evaluation guide

How to evaluate this model responsibly

ValidationStratified K-Fold; Group/StratifiedGroup K-Fold when samples share subjects or entities.
MetricsF1, ROC-AUC, PR-AUC, log loss and a confusion matrix; use balanced accuracy for imbalanced classes.
HPORandom search or Bayesian optimisation after a reasonable baseline; nested CV when tuning and unbiased performance estimation must be separated.
Post-processingTune decision thresholds and calibrate probabilities when downstream decisions use risk scores.
Hyperparameters

Key parameters

var_smoothingTypical: 1e-9

Variance stability term added to every feature.

Use & trade-offs

Where it fits

Typical applications

Real-time sentiment analysis, spam filtering, initial baseline classification on small datasets.

Strengths

Extremely fast to train and predict; requires very little training data to estimate parameters.

Limitations

Strong 'naive' conditional independence assumption rarely holds in real-world correlated data.

Code example

Minimal Python implementation

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score, confusion_matrix

# STEP 1 · Create a genuine three-class dataset.
X, y = make_classification(n_samples=180, n_features=6, n_informative=5,
                           n_redundant=0, n_classes=3, n_clusters_per_class=1,
                           class_sep=1.25, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.25, stratify=y, random_state=42)
print("STEP 1 · Classes:", sorted(set(y_train)))

# STEP 2 · Fit one Gaussian distribution per class and feature.
model = GaussianNB().fit(X_train, y_train)
print("STEP 2 · Class priors:", model.class_prior_.round(3).tolist())

# STEP 3 · Evaluate all three classes.
pred = model.predict(X_test)
print("STEP 3 · Accuracy:", round(accuracy_score(y_test, pred), 3))
print("Confusion matrix:")
print(confusion_matrix(y_test, pred))
Expected / representative output
STEP 1 · Create a small binary dataset
Train/test shapes: (67, 5) (23, 5)
STEP 2 · Fit GaussianNB
Class prior: [0.493, 0.507]
STEP 3 · Evaluate unseen rows
Test accuracy: 0.826
First predictions: [1, 0, 1, 1, 0, 1]