In a certain mail system of all messages are spam. Statistics show that of spam messages contain the word lottery, while only of legitimate messages contain it.
A message arrives that contains the word lottery. What is the probability that it is spam?
Name the events and sort the given numbers. Let = "the message is spam", = "the message is legitimate", and = "the message contains the word lottery". The data are
Notice the direction: you are given the probability of the word given the class, but asked for the class given the word. Reversing a conditional probability is exactly what Bayes' theorem is for.
Write down Bayes' theorem for the quantity asked.
The numerator is the probability of being spam and containing the word; the denominator is the probability of containing the word at all, over the whole mail stream.
Get the denominator from the law of total probability. Every message is either spam or legitimate, so those two cases partition the sample space:
So about one message in four contains the word — and most of that mass comes from the far larger pool of legitimate mail.
Substitute and simplify to an exact fraction.
Interpret the result and sanity-check it. Seeing the word raises the probability of spam from the prior to about — strong evidence, but still far from certainty, because legitimate mail is four times as common to begin with. A useful cross-check: of a notional messages, are spam and of those contain the word, while are legitimate and of those contain it. Of the flagged messages, are spam: , matching the formula.
Need to solve a different problem like this? Open the solver →