Bayes Theorem — AI Technical Interview Questions & Answers
Bayes Theorem
Bayes Theorem
- Bayes: P(H|E) = P(E|H) P(H) / P(E). Prior P(H), likelihood P(E|H), posterior P(H|E). Spam: H = spam, E = word “lottery”. A rare disease with a pretty-good test still has a modest posterior if the prior is tiny — classic trap.
- Always name prior, likelihood, posterior. Plug tiny numbers if they ask to compute. Don’t recite the formula with no story.
- Bayes Theorem — output: 0.8. After seeing lottery, spam belief jumps from 0.2 to 0.8.
prior P(H)
× P(E|H)
/ P(E)
▼
posterior P(H|E)Technical Interview Tip: Spam or disease story + name the three terms.
Code Examples for Bayes Theorem
Example
# Bayes — lottery word
# P(spam)=0.2 P(lottery|spam)=0.8 P(lottery|ham)=0.05
# P(lottery)=0.8*0.2 + 0.05*0.8 = 0.20
p_spam_given_lottery = (0.8 * 0.2) / 0.20
print(round(p_spam_given_lottery, 2))
Bayes Theorem — output: 0.8. After seeing lottery, spam belief jumps from 0.2 to 0.8.
How to Explain Bayes Theorem to an Interviewer
Explain Bayes Theorem as if you are teaching a junior — definition, then one example.
P(H|E) = P(E|H)P(H)/P(E) Prior / likelihood / posterior
What does the example print, and what does that prove?
Bayes Theorem — output: 0
What mistake do freshers make with Bayes Theorem?
ignoring the prior.