Naive Bayesian class probability greater than one

I have a problem with a simple Naive Bayes calculation. Given that I have an inbox, with the following characteristics:

• The mailbox contains 100 emails
• 50 emails contain the word “money”.
• 30 emails contain the word “viagra”.
• The user manually flagged 30 emails as spam, of which 25 emails contain the word “viagra” and 25 emails contain the word “money”, but we don't know which emails contain which words exactly.

So the probability of an email having both the words "money" and "viagra" to be spam should (emphasis on the should) be:

$$P(spam \mid money \cap viagra) = \frac{P(money \mid spam) P(viagra \mid spam)P(spam)}{P(viagra)P(money)}$$

But if I plug in the numbers I get: ~1.39 which is a probability greater than one. Is this due to the assumption of independence of the NB or did I get something wrong?

Unless I am mistaken, I believe the denominator of the formula is wrong. It should be

$$P(spam|money\cap viagra)=$$ $$\frac{P(money\cap viagra|spam)P(spam)}{P(money\cap viagra|spam)P(spam)+P(money\cap viagra| Not spam)P(Not spam)}$$

Give that a try and see if it fixes your problem.

• can I ask you how you got there and how I compute $$money \cap viagra \mid spam$$? Commented Aug 21, 2013 at 21:23
• I'm not saying its computable but that is the calculation you need to make. Also, here is the reference for Bayes Theorem en.wikipedia.org/wiki/Bayes%27_theorem
– user25658
Commented Aug 21, 2013 at 21:26
• but this is not including the "naive" assumption of independence between the events - is it? Commented Aug 21, 2013 at 21:55
• Okay, now I know what you mean by "naive". In that case just split up the probabilities and you should be able to still use the formula....
– user25658
Commented Aug 21, 2013 at 22:16
• ok I finally got the right results (hopefully!) - cheers Commented Aug 22, 2013 at 6:51