HomeMachine Learning & Neural NetworksNaive Bayes Classifier — Probabilistic Decision

📊 Naive Bayes Classifier — Probabilistic Decision

Classify 2D points with a Gaussian naive Bayes model: estimate per-class means and variances, apply Bayes' rule under the independence assumption, and render the posterior decision boundary.

Machine Learning & Neural Networks3DModerate60 FPS
naive-bayes ↗ Open standalone

About this simulation

This simulation shows a Gaussian naive Bayes classifier learning to separate points into 2 or 3 classes. For each class it fits a mean and variance along the x- and y-axes from the points you provide, treating the two axes as conditionally independent given the class — the "naive" assumption. Every pixel is then coloured by whichever class has the highest posterior probability under Bayes' rule, with shading strength showing the model's confidence, while the live accuracy readout tracks how well the fitted model reclassifies its own training points.

🔬 What it shows

A decision surface built from per-class Gaussians. Each class gets a mean marker and a one-standard-deviation ellipse computed from its points; the coloured background is the argmax-posterior region for every pixel, and because each class can have its own variance the boundary between classes is a curve, not a straight line.

🎮 How to use

Choose a preset (2 blobs, 3 blobs, or Overlap) or click the canvas to drop your own points into the selected class using the class buttons. Use the Classes slider to switch between 2 and 3 categories, then press Fit model to recompute the Gaussians and decision boundary, Clear points to start empty, or Reset to reload the current preset.

💡 Did you know?

Naive Bayes assumes features are independent given the class even when they are not — for example, height and weight are correlated in reality — yet the classifier is often still accurate in practice, and its speed and simplicity are why it remains a common baseline for text and spam classification.

Frequently asked questions

What is a naive Bayes classifier?

A naive Bayes classifier assigns each point to the class with the highest posterior probability, computed from Bayes' rule as proportional to the class prior times the likelihood of the point's features under that class. It is called "naive" because it assumes the features are conditionally independent given the class, which simplifies the likelihood into a product of per-feature probabilities.

How does this simulation estimate the probabilities?

For each class it computes the mean and variance of the x-coordinates and y-coordinates of its points, then models each axis as an independent Gaussian distribution. The class prior is simply the fraction of all points that belong to that class. Multiplying the prior by the two Gaussian likelihoods gives the (unnormalised) posterior used to classify any location.

Why is the decision boundary curved instead of straight?

When classes have different variances, the Gaussian likelihood terms do not cancel out linearly, so the argmax-posterior boundary becomes a curve, typically shaped like a parabola or ellipse arc. This quadratic boundary is a hallmark of Gaussian naive Bayes and is visible in the simulation whenever the class spreads differ, such as in the Overlap preset.

What does the accuracy percentage mean?

After you press Fit model, the simulation reclassifies every training point using the fitted Gaussians and reports the fraction that land back in their original class. This is training accuracy, not accuracy on new unseen data, so it mainly indicates how well the current Gaussian model separates the classes you have drawn.

Can I add more than 3 classes or draw my own data?

The Classes slider supports 2 or 3 categories, and you can always click anywhere on the canvas to add a point to whichever class is selected in the class picker. This lets you build custom, possibly overlapping or oddly shaped distributions and see how the fitted Gaussians and decision boundary adapt after pressing Fit model.

⚙ Under the hood

Classify 2D points with Gaussian naive Bayes: estimate per-class means and variances, apply Bayes' rule, and render the posterior decision boundary.

naive BayesclassificationGaussianposteriorCanvas 2D

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)