I can't find any solution

Hi, guys!

I got stuck in the assignment for Week 2.
The Naive Bayes model I constructed could output 0.0 and 9165
for print(logprior) and print(len(loglikelihood)), respectively.

However, testing of my model failed as shown in the picture above.
I think my implementation for the variable, freq_pos could have some problems.
Could you please give me some advice?

Hi @Setsuro_Matsuda

It’s hard to advice from just this error. I would comment that it is indicative that train_naive_bayes() function returns wrong loglikelihood value (even though the length of it is correct).

From the error it is visible that loglikelihood['sunglass'] has a key error (no sunglass in your loglikelihood dictionary). Maybe when you calculated the log likelihood of the word at the very end you forgot to assign it to loglikelihood[word]? Maybe in the for loop you did not loop through vocab? It could easily been something else.

If you are still stuck and cannot find a solution, you could private message me your Assignment notebook attached. (how to download your notebook)

For anyone in the future: If you encounter the same problem, pay close attention to

            # Increment the number of positive words by the count for this (word, label) pair
            N_pos += ?

        # else, the label is negative
        else:

            # increment the number of negative words by the count for this (word,label) pair
            N_neg += ?