Bayes' theorem Question

433 Views Asked by At

I encountered following question:

Consider that the occurrence of spam attachments in email messages is $1$ in $1500$.

  • Your email spam detector will correctly identify a mail as spam $97\%$ of the time.
  • Your email spam detector will also correctly identify a mail as non-spam $97\%$ of the time.
  • Your email spam detector has just flagged a mail as being spam mail.

What is the probability that the mail is actually not a spam?

I got $0.0667\,\%$ based on my calculation.

Can anyone help me with this and see if I am correct?

Thank you.

3

There are 3 best solutions below

3
On BEST ANSWER

Hmm I think you're wrong.

It should be $\frac{P(not\ spam\ but\ reported\ spam)}{P(reported\ spam)}=\frac{0.03*1499/1500}{0.03*1499/1500+0.97*1/1500}$

It might help by drawing a rectangle, let x axis be spam/not spam, y axis be report spam/ not report spam. And then color the corresponding parts and calculate the area.

0
On

Let $P(A) = 1/1500$ be the probability that a piece of mail is actually spam. Let $P(B)$ be the probability that the detector says a piece of mail is spam.

Then $P(B | A) = 0.97$ is the probability that the detector identifies the letter as spam when it actually is spam.

We also have $P(\lnot B | \lnot A) = 0.97$, the probability that the detector will say the piece of mail is not spam given that it's actually not spam.

To compute $P(\lnot A | B)$, the probability that the mail is not spam even though the detector said it was, we have:

$$P(\lnot A | B) = \frac{P(B | \lnot A)P(\lnot A)}{P(B)} = \frac{P(B | \lnot A)P(\lnot A)}{P(B|A)P(A) + P(B|\lnot A)P(\lnot A)} \\= \frac{(1-0.97)(1-1/1500)}{0.97(1/1500) + (1-0.97)(1-1/1500)} = 0.9789$$

0
On

It is useful to define some notation to describe the events of interest. Let $S$ denote the event that the email is spam, let $F$ denote the event that the message is flagged as spam. Similarly, let $\bar S$ and $\bar F$ denote the complementary events that the message is not spam and not flagged, respectively.

Then, we are given $$\Pr[S] = \frac{1}{1500}, \quad \Pr[F \mid S] = 0.97, \quad \Pr[\bar F \mid \bar S] = 0.97.$$ It is important to see how we translated the given conditional probabilities into the notation we defined; e.g., given that the message is spam, the probability that the message is correctly flagged is $0.97$.

We are asked to find $\Pr[\bar S \mid F]$; that is to say, given that a message was flagged, what is the probability that it is actually not spam?

The rest is simply Bayes theorem and the law of total probability: $$\Pr[\bar S \mid F] = \frac{\Pr[F \mid \bar S]\Pr[\bar S]}{\Pr[F]} = \frac{\Pr[F \mid \bar S]\Pr[\bar S]}{\Pr[F \mid S]\Pr[S] + \Pr[F \mid \bar S]\Pr[\bar S]}.$$ Note the first equality is Bayes theorem. The second, in which the unconditional probability in the denominator is expanded into the weighted sum of conditional probabilities, follows from the law of total probability.

Next, note that $$\Pr[F \mid \bar S] + \Pr[\bar F \mid \bar S] = 1.$$ This is because, given that a message is not spam, the only choices for the detection system is to either flag it, or to not flag it; i.e., we must observe exactly one of the events $F \mid \bar S$, or $\bar F \mid \bar S$. Therefore, $$\Pr[\bar S \mid F] = \frac{(1 - \Pr[\bar F \mid \bar S])(1 - \Pr[S])}{\Pr[F \mid S]\Pr[S] + (1 - \Pr[\bar F \mid \bar S])(1 - \Pr[S])} = \frac{(1 - 0.97)(1 - 1/1500)}{(0.97)(1/1500) + (1 - 0.97)(1 - 1/1500)}.$$


There are some important things to observe about the method of solution. First, note how we chose appropriate letters for the events, so $S$ is for "spam", and $F$ is for "flagged." This improves interpretability and reduces the chance of getting mixed up by your notation, since in such problems, the order in which conditional events are specified matters. The other thing to observe is that we need to be familiar with many properties of probability, and to be able to draw upon them at a moment's notice. Specifically, it is not enough to simply know Bayes theorem: we need to know other properties of probability. This allows a clear solution path and prevents us from getting stuck.