C1_W2_Assignment loglikelihood wrong value

my values for logprior and loglikelihood are 0.0, 9147 respectively, it matches expected outcome but the test fails

9147 is just the number of entries in the dictionary. What the test is telling you is that the actual values of those entries must be incorrect.

I added the following lines of debugging code in my train_naive_bayes function in the loop over all the words:

        if word == 'smile':
            print(f"freq_pos for smile = {freq_pos}")
            print(f"freq_neg for smile = {freq_neg}")
            print(f"loglikelihood for smile = {loglikelihood[word]}")
        if word == 'lawnmow':
            print(f"freq_pos for lawnmow = {freq_pos}")
            print(f"freq_neg for lawnmow = {freq_neg}")
            print(f"loglikelihood for lawnmow = {loglikelihood[word]}")

When I run the test cell for that function, here is what I see:

V: 9147, V_pos: 5789, V_neg: 5617, D: 8000, D_pos: 4000, D_neg: 4000, N_pos: 27212, N_neg: 26705
freq_pos for lawnmow = 1
freq_neg for lawnmow = 0
loglikelihood for lawnmow = 0.6791047678742651
freq_pos for smile = 47
freq_neg for smile = 9
loglikelihood for smile = 1.554573505228165
0.0
9147

Please try that experiment and see if you get the same values or not.

here’s the answer i got

I solved it already, Thank you

That’s great news! Thank you for confirming.

how to reset the changes of the notebook as the instructions link doesn’t work.

what do you mean reset changes, are you looking for fresh copy of assignment @soumen2025

yes looking for fresh copy.

Hi @soumen2025

Please follow below steps mentioned

  • Open your current notebook.
  • Go to “File->Rename”, and rename the notebook.
  • Go to the Lab Help menu (the question-mark inside a circle), and use “Get latest version”.
  • Go to “File->Open” menu, and open the new notebook.
  • Use the “Kernel->Restart & Clear All Output” command.

Now the new notebook is ready for you to use.

Note: Do not rename the new notebook. The grader always uses the notebook with the original file name.

Regards

DP