ML
beginner
Naive Bayes Classifier
Probabilistic classifier based on Bayes' Theorem! See how prior probabilities and likelihoods combine to make predictions. The foundation of spam detection and text classification.
algorithms.live
Test Point
50
50
Dataset
42
View Options
Naive Bayes
Class 0
Class 1
Test Point Prediction:
Class 0
Blue
P(Blue):84.3%
P(Red):15.7%
Class 0 Parameters
μx: 29.40
μy: 40.45
σx: 8.22
σy: 8.34
P(Class 0): 50.0%
Class 1 Parameters
μx: 68.76
μy: 60.15
σx: 6.68
σy: 4.73
P(Class 1): 50.0%
Live Computation for Test Point (50, 50)
Class 0
Prior P(C0)50.0%
P(x | C0)2.10e-3
P(y | C0)2.48e-2
Unnorm. posterior2.61e-5
P(C0 | x,y)84.3%
Class 1
Prior P(C1)50.0%
P(x | C1)1.15e-3
P(y | C1)8.43e-3
Unnorm. posterior4.85e-6
P(C1 | x,y)15.7%
Prediction: Class 0 — because P(C0|x,y) = 84.3% > P(C1|x,y) = 15.7%
The Naive Independence Assumption
P(x, y | Class) = P(x | Class) × P(y | Class)
Instead of modelling the joint distribution of all features (exponentially complex), we model each feature separately and multiply. This is almost always wrong — but usually gives the right answer.
Why It Works Despite the Lie
Even though the posterior probabilities are wrong (too extreme, too confident), the *ranking* between classes is usually preserved. Ranking is all you need for classification. The model is overconfident but rarely picks the wrong class.
Training is Trivial
Just compute mean and standard deviation of each feature in each class. No gradient descent, no hyperparameters, no iterations. With n features and k classes: store 2nk numbers. Prediction is just evaluating Gaussian PDFs.
The Ellipses Are Axis-Aligned
Because x and y are treated as independent, the 2σ ellipses are always axis-aligned (no rotation). Real data often has tilted ellipses (correlation between features). Quadratic Discriminant Analysis (QDA) handles this by modelling the full covariance matrix.
Classify a document with Naive Bayes
Sequence
Order the computation.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
- 5Drop a step here
5 pieces left to place
Test your knowledge
20 questions
Question 1 of 20
Score: 0
Naive Bayes classifiers are based on which theorem?
Learn these first
Interview Questions
Google
Yahoo
Microsoft
Amazon
Apple
IBM
LinkedIn
Salesforce
HubSpot
Facebook
Twitter
Snap
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required