machinelearninginaction3x
machinelearninginaction3x copied to clipboard
Chapter 4 - Classifying with probability theory: naïve Bayes
When we attempt to classify a document, we multiply a lot of probabilities together to get the probability that a document belongs to a given class. This will look something like p(w0|1)p(w1|1)p(w2|1). If any of these numbers are 0, then when we multiply them together we get 0. To lessen the impact of this, we’ll initialize all of our occurrence counts to 1, and we’ll initialize the denominators to 2
First of all, huge thanks for creating an understandable ML book.
Coming back to question now:
I perfectly, understood the idea behind setting p0Num
and p1Num
to np.ones
, but why you have set p0Denom
and p1Denom
both to 2?
In my opinion, it should be set to the length of the myVocabList
multiplied by 1.
p0Denom = sum(p0Num) p1Denom = sum(p1Num)