How is naive Bayes drawn as a graphical model, and what is its independence assumption? A spam filter has P(spam)=0.4. The word "offer" appears in 60% of spam and 10% of ham (non-spam) emails; the word "meeting" appears in 30% of spam and 50% of ham. Using only these two words, what is P(spam∣offer,meeting) for an email that contains both?

Probabilistic models, Naive Bayes
Level L2 Elementary. Length Medium. Nature Th+Mat Both.

What's being asked

Whether you can turn the graph's assumption into a factorised likelihood and run Bayes' rule with numbers.

Key idea

In naive Bayes the class Y is the only parent of every feature, so features are conditionally independent given the class: p(y,x1,…,xd)=p(y)∏jp(xj∣y), and therefore P(y∣x)∝p(y)∏jp(xj∣y).

Steps

  1. Draw Y with an arrow to each Xj and no edges between features. State Xi⊥Xj∣Y.
  2. Write the posterior: P(spam∣x)=P(spam)∏jp(xj∣spam)∑yP(y)∏jp(xj∣y) The denominator just makes the two class probabilities add up to 1.
  3. Spam score: 0.4×0.6×0.3=0.072. Ham score: 0.6×0.1×0.5=0.030.
  4. Normalise: P(spam∣x)=0.072/(0.072+0.030)=0.072/0.102≈0.706.
  5. Comment: the independence assumption is usually false (words co-occur), so the probabilities are poorly calibrated, but the argmax is often still right. Mention Laplace smoothing for words never seen with a class, and summing logs to avoid underflow.

Common mistakes

How long your answer should be

The graph, the formula and a four-line computation; 2–3 minutes.

Last checked on 4 December 2026.

Read this

Previous in Probabilistic models: Two neighbouring pixels in a photo are usually the same colour, but neither one causes the other. How can a plain undirected link with agreement scores describe this, and how are the scores turned into probabilities?
Next in Probabilistic models: An HMM has hidden states Rainy (R) and Sunny (S), initial probabilities π=(0.6,0.4), transitions P(R→R)=0.7, P(R→S)=0.3, P(S→R)=0.4, P(S→S)=0.6, and emissions P(walk∣R)=0.1, P(shop∣R)=0.4, P(walk∣S)=0.6, P(shop∣S)=0.3. Using the Viterbi algorithm, what is the most likely hidden sequence for the observations (walk, shop)?