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?


1 Answer 1


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.

  • $\begingroup$ can I ask you how you got there and how I compute $$ money \cap viagra \mid spam $$? $\endgroup$
    – luke14free
    Commented Aug 21, 2013 at 21:23
  • $\begingroup$ 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 $\endgroup$
    – user25658
    Commented Aug 21, 2013 at 21:26
  • $\begingroup$ but this is not including the "naive" assumption of independence between the events - is it? $\endgroup$
    – luke14free
    Commented Aug 21, 2013 at 21:55
  • $\begingroup$ 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.... $\endgroup$
    – user25658
    Commented Aug 21, 2013 at 22:16
  • $\begingroup$ ok I finally got the right results (hopefully!) - cheers $\endgroup$
    – luke14free
    Commented Aug 22, 2013 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.