Two classes, two observed features
For two classes A and B with P(B)=1−P(A), let x1 and x2 be values already observed. The calculator takes P(X1=x1|A), P(X2=x2|A) and the corresponding two values for B. All five inputs are probabilities between 0 and 1. Discrete-event feature probabilities may be zero. The inputs are neither measurements nor probability densities.[1][2]
Why the factors and normalization are needed
The Bayes theorem gives P(A|x)=P(A)P(x|A)/P(x). Only the additional assumption P(x1,x2|A)=P(x1|A)P(x2|A) permits the naive factorization. This independence is assumed within each class; it does not require unconditional independence of the features. The common denominator may be omitted when merely comparing positive scores, but is needed when reporting probabilities.[1][2]
For a binary feature observed as x2=0 and presence probability θ=P(X2=1|A), the input factor is 1−θ. If the probability of the value actually observed is already supplied, use it directly. Taking a second complement would be wrong. This is the event convention of this calculator; a multinomial word-count model has a different observation structure.[1][2]
The calculator sums logarithms and normalizes stably. Mathematically zero factors are handled separately. LSE denotes log(exp(ℓA)+exp(ℓB)); the direct exponential sum is not a numerical instruction.[1][2]
How the prior changes the posterior
Free with a Quanta account. Your download stays ready after registration.
Two fully worked examples
Using an observed absence correctly
- Given
- P(A)=P(B)=0.5; x1=1, x2=0. For A: P(x1|A)=0.8 and P(x2|A)=0.25. For B: 0.3 and 0.9.
- Find
- Find both posteriors and the preferred class.
The factors for x2=0 are already given; take no further complement.
The common evidence is the sum of both scores.
Result: P(A|x)≈0.425532 and P(B|x)≈0.574468. The model prefers B.
Check: Both posteriors sum to 1. The scores alone sum to only 0.235, so they are not the reported class probabilities.
Strong evidence can outweigh a small prior
- Given
- P(A)=0.2; P(B)=0.8. The observed feature likelihoods are 0.9 and 0.5 for A, and 0.1 and 0.5 for B.
- Find
- Calculate P(A|x) and check it as a change in odds.
Priors and feature products form the scores.
Normalize and independently check the odds.
Result: P(A|x)≈0.692308; P(B|x)≈0.307692. The evidence reverses the initial preference for B.
Check: The likelihood ratio 9 multiplies prior odds 1/4 into posterior odds 9/4. Equal likelihoods for the second feature cancel in the ratio.
Recall the method later with the formula’s flashcards.
11 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Five solved exercises with different learning goals
Calculate · Foundation
The scores are sA=0.1 and sB=0.135. Calculate both posteriors.
Show hint
Define the quantities first and apply the stated model.
Learning goal: Normalize scores to a complete class distribution.
Show solution and calculation
Z=0.235; P(A|x)=20/47≈0.425532 and P(B|x)=27/47≈0.574468.
Rearrange · Application
With fixed sB=0.04, require P(A|x)=2/3. What score sA is needed?
Show hint
Define the quantities first and apply the stated model.
Learning goal: Distinguish a conditional inversion from a nonunique inversion of the model.
Show solution and calculation
From q=sA/(sA+sB), sA=q sB/(1−q).
Thus sA=(2/3)×0.04/(1/3)=0.08.
This fixes one score, not a unique decomposition into prior and features.
Interpret · Foundation
Both classes have the same positive likelihood for the whole observation. P(A)=0.2. What is the posterior of A?
Show hint
Define the quantities first and apply the stated model.
Learning goal: Recognize neutral evidence from equal likelihoods.
Show solution and calculation
The equal likelihood cancels: P(A|x)=0.2/(0.2+0.8)=0.2.
Here the observation does not change class odds.
Error analysis · Application
X2=0 is observed. P(X2=1|A)=0.75 is given. A calculation uses factor 0.75. Correct it.
Show hint
Define the quantities first and apply the stated model.
Learning goal: Check the definition of the observation before multiplying.
Show solution and calculation
For the observed value, P(X2=0|A)=1−0.75=0.25.
Use that factor once.
If 0.25 had already been given as the probability of the observed value, it must not be complemented again.
Transfer · Challenge
X2 is an exact copy of X1. With equal priors, P(X1=1|A)=0.8 and P(X1=1|B)=0.2. Compare the correct posterior for two observed ones with naive duplication.
Show hint
Define the quantities first and apply the stated model.
Learning goal: Assess a violated conditional-independence assumption with a counterexample.
Show solution and calculation
Because X2=X1, the joint likelihoods are 0.8 and 0.2; the correct P(A|x)=0.8.
Incorrect independent multiplication gives 0.82/(0.82+0.22)=16/17≈0.941176.
It counts the same evidence twice.
Check your understanding with the formula’s reference test.
8 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Limits, measurements and calculator
The calculator trains no model and tests neither empirical independence nor calibration. It computes two posteriors or the natural logarithm of P(A|x) from five supplied probabilities. A tie remains a tie. Two mathematically zero scores give no defined posterior; inventing 0.5 would not be a Bayes solution.[1][2]
Positive factors near 10−250 can underflow to zero when multiplied directly. Logarithmic evaluation often preserves the ratio, such as 0.5 for equal class factors. If a positive posterior still falls outside the representable positive range or rounds to exactly 1, the probability output reports that representation limit. Its logarithm may remain useful. Actual zero factors are treated separately.[1][2]
Laplace smoothing changes frequency estimates using counts and pseudocounts. It is a separate model decision. This calculator adds no hidden smoothing and does not replace an unknown zero with an arbitrary small number. The connection to the Bayes theorem remains normalization of the explicitly selected model.[1][2]
Sources for this explanation
Quanta · Updated November 9, 2026
- scikit-learn User Guide: Naive Bayes — Introduction: conditional independence and posterior factorization; §1.9.4 Bernoulli Naive Bayes: absence is part of the observation.
- UC Berkeley CS 188: 9.2 Naive Bayes — §9.2 model factorization; §9.2.2 frequency estimation; §9.2.3 Laplace smoothing with explicit pseudocounts.
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Standalone article with normalized posteriors, observed features and a bounded logarithmic calculator.
Cite this reference page
Quanta. Naive Bayes classification. Updated November 9, 2026. https://quanta-study.de/en/formula-sheet/naive-bayes-klassifikation
When citing a specific scientific statement, also cite the specialist source linked to that statement.