Naive Bayes Classifier Calculator

Read the Theory Guide →

Enter labeled examples with categorical features, fill in a Target row, and calculate a predicted class. The solver shows the class priors, the conditional probabilities for each feature value, and the combined score for each class.

What You Can Explore

  • Edit the categorical feature values and class labels, and add or remove rows to change the training data.
  • Fill in the Target row with one value for each feature to choose the case you want to classify.
  • Press Calculate Probabilities to see the prior probability of each class, the conditional probabilities for the Target values, and the final score for each class.
  • Follow each class's calculation from its prior through the feature probabilities to see why one class receives the higher score.
Core Mechanics
▼
  • The Missing Denominator: In standard probability, you divide by the total probability of the evidence. In Naive Bayes, we skip that! Since the denominator is the exact same for every class, we just compare the numerators and pick the biggest one to save time.
  • The "Naive" Assumption: The algorithm gets its name because it assumes every single feature is completely independent. It blindly multiplies their individual probabilities together, completely ignoring how features might actually interact in the real world.
  • Multiply and Conquer: To make a prediction, you simply take the base probability of a class (the Prior) and multiply it by the probability of each feature matching that class. It's just one long chain of multiplication!
  • The Zero-Frequency Trap: If a specific feature value never appeared with a class in your data, its probability is zero. Because we multiply everything, that single zero wipes out the entire score! Note: While "Laplace Smoothing" is the standard industry fix for this, this solver runs pure, unsmoothed calculations to match introductory exams.
Initializing Workspace...

Understanding Your Result

The prediction comes from the class counts and feature values in your data, together with the values in the Target row. Each class starts with a prior probability, then the relevant feature probabilities are multiplied together to produce a final Naive Bayes score. The class with the highest score becomes the prediction.

  • Step 1 gives each class its prior probability based on how often that class appears in the training data. A class with more examples starts with a larger prior.
  • Step 2 gives P(feature value | class) for every Target value. These probabilities show how common each feature value is within each class.
  • Step 3 multiplies the prior by the conditional probabilities for the Target values. These are raw scores rather than normalized probabilities, so they do not have to add up to 1. The highest score determines the predicted class.
  • With no smoothing, a conditional probability of 0 makes the entire score for that class 0. A small difference between the final scores also means a small change in the data or Target values can change the prediction.

Try These Experiments

Use a Value One Class Has Never Seen

Setup: Run the preloaded table with the default Target row. The predicted class is No, with a score of about 0.0183 for No and 0.0106 for Yes.

Action: Change the Target Age from >40 to 31...40, leave the other Target values unchanged, and calculate again.

What to Observe: Step 2 shows P(31...40 | No) = 0/5. That zero makes the entire No score become 0. The Yes score is about 0.0141, so the prediction changes to Yes.

Takeaway: Without smoothing, one unseen feature value can completely eliminate a class from consideration. Once one factor becomes 0, multiplying it with the other probabilities still gives 0.

Relabel One Training Example

Setup: Run the preloaded table and note the class priors: 5/14 for No and 9/14 for Yes. The No score is about 0.0183, compared with about 0.0106 for Yes.

Action: Change the class label of the last row (>40, Medium, No, Excellent) from No to Yes, then calculate again.

What to Observe: The priors change to 4/14 for No and 10/14 for Yes, and several conditional counts change as well. The final scores become about 0.0134 for No and 0.0137 for Yes, so the prediction changes to Yes.

Takeaway: A single training example can affect both the class prior and the conditional probabilities. When the final scores are close, even a small change in the training data can reverse the prediction.

Change One Target Feature

Setup: Run the preloaded table with the default Target row, where Is_Student is No. The Yes score is about 0.0106 and the No score is about 0.0183.

Action: Change only Is_Student in the Target row from No to Yes, then calculate again.

What to Observe: The Yes score rises to about 0.0212, while the No score falls to about 0.0046. The predicted class changes from No to Yes.

Takeaway: Each Target feature contributes its own conditional probability to a class's score. Here, Is_Student = Yes is much more common among Yes examples than No examples, so changing just that feature strongly shifts the result.