Concepts and worked examples

Probability, Evidence, and Naive Bayes

Use base rates and new evidence to reason about probability and Naive Bayes.

Joint and conditional probability

P(A) means the chance that event A happens. P(A ∩ B) is the chance that both A and B happen. P(A | B) asks for the chance of A only among cases where B happened. Looking at that smaller group can change the answer.

P(A | B) = P(A ∩ B) / P(B)
P(A ∩ B) = P(A | B)P(B) = P(B | A)P(A)

Independence means learning B does not change the probability of A: P(A | B) = P(A), when defined. Only then does the joint simplify to P(A)P(B). Mutual exclusivity is different: two nonzero-probability events that cannot occur together are not independent. Reversing a conditional without accounting for base rates is another common error.

Bayes' rule: update a prior with evidence

P(C | E) = P(E | C)P(C) / P(E)
P(E) = P(E | C)P(C) + P(E | not C)P(not C)

The prior P(C) is belief about class C before observing evidence E. The likelihood P(E | C) describes evidence under that class, not the probability of the class. Evidence P(E), sometimes called the marginal likelihood, normalizes the result. The posterior P(C | E) is the updated class probability. For multiple mutually exclusive, exhaustive classes, evidence is the sum of likelihood times prior across all classes.

Worked example: an accurate-looking rare-event alert

Suppose 1% of transactions have a costly processing error. An alert detects 90% of actual errors and alerts on 5% of error-free transactions. In 10,000 representative transactions, expect 100 errors and 9,900 non-errors. The alert flags 90 errors and 495 non-errors, so 585 alerts contain only 90 errors.

Expected counts among 10,000 transactions
Actual outcomeAlertNo alert
Error9010
No error4959,405

P(error | alert) = (0.90 × 0.01) / (0.90 × 0.01 + 0.05 × 0.99) = 0.009 / 0.0585 ≈ 0.1538

Thus alert precision is about 15.4%, not 90%. The 90% figure is sensitivity, or recall. If correcting a genuine error saves 100 units and every review costs five, expected net value per alert is 0.1538 × 100 − 5 ≈ 10.38 units, assuming review successfully resolves the error. A modest posterior can still support a useful action.

Naive Bayes and sparse evidence

Directly estimating the likelihood of a complete feature vector can require many observations of combinations that rarely repeat. Naive Bayes replaces that joint likelihood with a product of feature likelihoods conditional on the class. Its assumption is conditional independence given the class, not unconditional independence of all features.

score(c) = P(c) × ∏ⱼ P(eⱼ | c)
P(c | e₁, …, eₖ) ≈ score(c) / Σ_d score(d)

For classification, choose the largest score; the common denominator does not affect that choice. To report probabilities, normalize over classes. Log scores, log P(c) + Σⱼ log P(eⱼ | c), avoid numerical underflow. Bernoulli, multinomial, and Gaussian variants make different assumptions appropriate to binary features, counts, or continuous measurements.

A zero estimated likelihood can erase an entire class score. With K categorical outcomes, additive smoothing estimates P(e = v | c) = (count(v,c) + α)/(N_c + αK). For example, a category unseen among eight class-c observations has probability 1/(8 + 3) = 1/11 with three categories and α = 1. The denominator must match the modeled event space; token-count models use class token totals rather than document totals.

Correlated evidence can change the answer

Important clarification: double-counting correlated evidence can damage classification as well as probability estimates. Suppose prior class odds are 1:9 and a feature's likelihood ratio is four. Correct updating yields posterior odds 4:9, or probability 4/13 ≈ 0.308. Duplicating that same feature and treating the copies as independent yields odds 16:9, or 0.64, flipping a 0.5-threshold decision.

Naive Bayes remains a useful efficient baseline, especially for text, but good classification does not guarantee calibration. Check probability reliability on representative held-out data. Incremental learning updates class counts and sufficient statistics as labeled observations arrive; it need not reread all historical examples. Changing vocabularies, concept drift, or inconsistent preprocessing still require explicit management.

Evidence lift and worked examples

Evidence lift for class c is P(E | c)/P(E) = P(c | E)/P(c). In the alert example it is 0.90/0.0585 ≈ 15.38: the alert raises error probability by that factor relative to the prior. This differs from the likelihood ratio P(E | c)/P(E | not c), which is 18 and multiplies prior odds.

Why does a high true-positive rate not imply high precision?

Precision depends on false positives and prevalence as well as sensitivity. A large non-error population can generate more false alerts than true alerts even with a small false-positive rate.

Can more evidence make Naive Bayes worse?

Yes. Redundant or shifted features can distort relative scores and confidence. Validate feature additions rather than assuming every extra measurement improves decisions.

Related: tree probabilities and logistic probabilities.

Definition

View in glossary →