In Dataquest’s Naive Bayes for Sentiment Analysis mission, screen 4;
there is an equation to predict as following using Laplace smoothing
def make_class_prediction(text, counts, class_prob, class_count):
prediction = 1
text_counts = Counter(re.split("\s+", text))
for word in text_counts:
# For every word in the text, we get the number of times that word occurred in the reviews for a given class, add 1 to smooth the value, and divide by the total number of words in the class (plus the class_count, also to smooth the denominator)
# Smoothing ensures that we don't multiply the prediction by 0 if the word didn't exist in the training data
# We also smooth the denominator counts to keep things even
prediction *= text_counts.get(word) * ((counts.get(word, 0) + 1) / (sum(counts.values()) + class_count))
# Now we multiply by the probability of the class existing in the documents
return prediction * class_prob
using
print("Negative prediction: {0}".format(make_class_prediction(reviews[0][0], negative_counts, prob_negative, negative_review_count)))
My questions are
-
When Lapace Smoothing is applied in the predict equation we add 1 (k=1) and in the denominator it should be as if we add one word to the who dataset so why is there (negative_review_count i.e number of negative reviews in the reviews array and has no count of the words in it)
-
When we add the extra count of words should that only be adding the count of all negative + positive both words right?
Could someone please help clarify? Thanks