The three terms are \(P(\text{B}|0)\), \(P(\text{A}|2)\) and \(P(\text{B}|3)\), which are the observed labels.
by hand: -17.143619
sklearn: -0.000412
log_loss with normalize=False is the negative log-likelihood. The two agree.
Move the two parameters and watch the log-likelihood. The dashed line is the generator that produced the data. Maximum likelihood picks the parameters that make the observed labels as probable as possible.
With three data points the fit is far from the generator. This is not a bug. It is what fitting three points looks like.
With two predictors the probability is a surface and the decision boundary is a line. Move the threshold and watch the boundary shift without the probability changing at all.
Spam classification
The input is text, so we need a representation. Bag of words counts how often each word occurs in each email.
Bag of words. Each column counts how often one word occurs in one email.
2
Divided by the length of the email, so that a long email does not dominate.
emails: 2000 vocabulary: 28128
Each word is one predictor, so \(p\) is in the tens of thousands while \(n\) is 2000. With \(p > n\) the training data can be fitted perfectly, and it will be. This is why week 4 is about regularization.