Naive Bayes – Using Laplace Smoothing (k = 1)

naive bayes

I used R to predict the event A = "yes" given certain parameters for B1, B2. The results are P(A = "yes"|B1 = "a", B2 = "b") = 0.88. And P(A = "no"|B1 = "a", B2 = "b") = 0.12. But when I did it in Excel, I got P(A = "yes"|B1 = "a", B2 = "b") = 0.81. It cannot be right as all other conditional probabilities in R and Excel are precisely the same. What formula do you we use in R to calculate P(A = "yes"|B1 = "a", B2 = "b"). I used
1. Laplace smoothing (k = 1)
So I used (count +k)/(N + k * |class|) for prior probabilities and added 1 to all counts prior to calculating conditional probabilities.
2. I used Bayes' Thm.
P(A = "yes" | B1 = "a", B2 = "b") = (P(B1 = "a")|A= "yes") * P(B2 = "b"|A = "yes") * P(A = "yes"))/P(B1 = "a", B2 = "b"), where
P(B1 = "b1", B2 = "b2") = P(B1 = "a"|A= "yes") * P(B2 = "b"|A = "yes") * P(A = "yes") + P(B1 = "a"|A= "no") * P(B2 = "b"|A = "no") * P(A = "no")

What am I doing wrong? Why are my answers not the same?

Best Answer

The answer is that when we calculate the posterior probability with Laplace smoothing, Laplace smoothing with k= 1 is applied only to conditional probabilities but not prior probabilities (since they are not zeros). That is the reason why the answer was a bit off.