Source: https://goodhandover.co.uk/tools/naive-bayes-calculator/

[Computer science maths](https://goodhandover.co.uk/tools/computer-science-maths/#year-3) / Year 3

🔒 Files never leave your device

# Bernoulli naive Bayes calculator

Calculate binary class posteriors from feature presence and absence. Your inputs stay on your device.

## Set up your task

Ready. Processing stays in this browser.

Files and text stay on your device. [Privacy details](https://goodhandover.co.uk/privacy/).

 

## How to use Bernoulli naive Bayes calculator

Calculate binary class posteriors from feature presence and absence. The pre-filled problem gives you a worked starting point. Compare the response with your own working before trying the self-check below.

 

- Check the example inputs: Prior P(class A), P(feature present | A), P(feature present | B), Observed features (0 or 1).

- Change the inputs for your problem. Results update as you type, so finish entering the values before copying an answer.

- Use the working to check an intermediate value or assumption. Then change the example as suggested in the self-check and compare the result.

 

## Supported inputs and limits

Enter a prior for A, paired conditional feature probabilities for A and B, and a matching 0/1 observation vector of up to 64 features.

 

## How it works

Bernoulli naive Bayes models a vector of binary features. For each class, a present feature contributes its conditional presence probability. An absent feature contributes one minus that probability. Multiplying by the class prior gives the joint contribution of the class and observed evidence.

The conditional independence assumption allows the feature terms to be combined even when the input is large. This implementation adds logarithms before normalising, which keeps products of many small probabilities from disappearing through floating-point underflow. The model here takes supplied probabilities. Estimating them from training data is a separate step.

 

## Example

Run the pre-filled example. Its first result is “P(A | evidence): 0.8”.

Prior P(class A)

0.5

P(feature present | A)

0.8 0.2

P(feature present | B)

0.4 0.6

Observed features (0 or 1)

1 0

P(A | evidence): 0.8
P(B | evidence): 0.2
Log joint scores: -1.13943428  -2.52572864
The features are assumed conditionally independent within each class.

 

## Questions about Bernoulli naive Bayes calculator

### Why do the log joint scores sometimes show negative infinity?

A zero factor makes a joint probability zero and its logarithm negative infinity. A posterior can still be computed if the other class gives the evidence positive weight.

### Does the model use absence information?

Yes. The Bernoulli model explicitly includes complements for absent features, in contrast to count-focused models typically taught alongside it.

### Give both classes identical feature probabilities.

When the evidence has positive probability, the posterior equals the prior. The observed features cannot distinguish the classes under those probabilities.

 
 

## Related tools

[Year 3: Advanced and applied maths](https://goodhandover.co.uk/tools/computer-science-maths/#year-3)

- [ROC AUC calculator](https://goodhandover.co.uk/tools/roc-auc-calculator/)

- [Softmax and cross-entropy calculator](https://goodhandover.co.uk/tools/softmax-calculator/)

- [Confusion matrix calculator](https://goodhandover.co.uk/tools/confusion-matrix-calculator/)

- [Gradient descent calculator](https://goodhandover.co.uk/tools/gradient-descent-calculator/)

 

Last updated 24 November 2026
