Update Beliefs with Bayes
A fruit box is chosen at random: A with probability 80%, B with 20%. Red fruit makes up 25% of A and 75% of B. If the selected fruit is red, which box is the more likely source?
Include the original proportions
Bayes’ theorem updates probabilities after an observation.
- Prior: Probability of A before observing color,
P(A)=0.8. - Likelihood: Probability of red given A,
P(red|A)=0.25. - Posterior: Probability of A after seeing red,
P(A|red).
red_from_a = 0.8 * 0.25
red_from_b = 0.2 * 0.75
posterior_a = red_from_a / (red_from_a + red_from_b)
print(round(posterior_a, 3))
The result is 0.571. Because A is chosen much more often, its posterior remains higher despite its smaller red-fruit proportion. Likelihood and posterior reverse the direction of conditioning.
With several features
Naive Bayes multiplies feature likelihoods under the assumption that features are independent given the class. It can be useful without perfect independence, but duplicating strongly related features can distort probability estimates. This assumption is specific to naive Bayes, not every Bayesian method.
An unseen event can also receive an estimated probability of zero. Practical classifiers consider smoothing to reduce this problem.
Check your understanding
Why are ‘red given A’ and ‘A given red’ different probabilities?
Show explanation
They use different populations. The first examines fruit from A; the second examines red fruit from both boxes. The second also needs box-selection proportions and the likelihood of red fruit in B.