PythiloLesson 10 of 12 · progress kept in this browser

Multinomial Naive Bayes

Count tokens per class with Laplace smoothing. Work in log space to avoid multiplying tiny probabilities; repeated tokens contribute repeatedly.

import math
print(math.log(0.5) + math.log(3/4))
Your task

log_scores(documents, labels, query, vocabulary) returns log posterior scores (without normalization) for classes 0 and 1. Both classes have documents; vocabulary is nonempty and unique. Ignore query tokens outside vocabulary, use alpha=1 and empirical class priors.