How to use the Naive Bayes Calculator
- 1. Paste training dataAdd a header row, feature columns and the class label in the last column.
- 2. Enter a new exampleType its feature values in the same order and choose the smoothing α.
- 3. ClassifySee the prior, each likelihood, the product and the posterior for every class.
How Naive Bayes decides
Naive Bayes uses Bayes' theorem with one simplifying ("naive") assumption: features are independent once you know the class. For each class it multiplies the class's prior, its share of the training rows, by the probability of each feature value in that class. Then it normalises the products so they add up to 1. The class with the biggest posterior wins.
Categorical columns use counts with Laplace smoothing, (count + α) ÷ (class count + α × number of values), so a value never seen with a class doesn't zero everything out. Numeric columns use a normal (Gaussian) curve fitted to each class.
Worked example
The sample is the classic 14-day "play tennis" table. For a Sunny, Cool, High humidity, Strong wind day with α = 1, class No has prior 5/14 = 0.3571 and likelihoods 0.5, 0.25, 0.7143 and 0.5714, a product of 0.01822. Class Yes has prior 0.6429 and likelihoods 0.25, 0.3333, 0.3636 and 0.3636, a product of 0.007084. Normalised, that's No 72.01% and Yes 27.99%, so the prediction is No.
Things to know
- Our results match scikit-learn's CategoricalNB (categorical columns) and GaussianNB (numeric columns), checked on 25 random datasets.
- The independence assumption is rarely true, yet Naive Bayes often classifies well, especially for text.
- Its probabilities can be over-confident; treat them as scores rather than exact chances.
- Data stays in your browser.
Frequently asked questions
What does α = 0 do?
It turns smoothing off, so the probabilities are plain counts. If the new example has a value never seen with a class, that class gets probability 0.
Can I mix numbers and categories?
Yes. Columns where every value is a number are treated as Gaussian; the others as categorical.
Is the Naive Bayes calculator free?
Yes. You can open the Naive Bayes calculator and enter everything without signing up. When you classify an example for the first time, we ask once for your name and WhatsApp number; after that it, and every other Uncodemy tool, opens straight away.