Code Has Been Removed
This is the code I have written for train_naive_bayes function. But while running the code for w2_unittest.test_train_naive_bayes function, 3 test cases are failed! I am not getting the reason. Please help!
Code Has Been Removed
This is the code I have written for train_naive_bayes function. But while running the code for w2_unittest.test_train_naive_bayes function, 3 test cases are failed! I am not getting the reason. Please help!
Hi @PG_Coursera
You can’t share your code here, but feel free to send the error message, and we’ll provide some hints to help you fix the issue!
However, let’s check your code:
vocab
should be a set of unique words, not the entire freqs
dictionary. Also, V
should be the number of unique words (len(vocab)
).
Print values when populating words
and make sure the process of populating it is correct.
Hope this helps! Feel free to ask if you need further assistance.
I hope that you have made some changes to the code that you showed 8 days ago. As Alireza pointed out there were a number of problems with it. We aren’t supposed to share the code in a public way, but I will send you a DM about how to get the code reviewed in detail.
@Lukasz_Przewoznik @PG_Coursera 0 I seem to be having the same issue with the train_naive_bayes function (same error message with 12 working test cases and three fails. I have gone back over the formulas and believe I am doing them correctly. It is not complicated code. I have checked each of the formulas carefully from top to bottom and I cannot figure out what I am doing wrong here. It seems very straightforward.
I did use the set command to make sure I wasn’t repeating words in my vocabulary and set V to the length of the set.
I am using the numpy log function and the expected values are correct.
error: Wrong values for loglikelihood dictionary. Please check your implementation for the loglikelihood dictionary.
Wrong values for loglikelihood dictionary. Please check your implementation for the loglikelihood dictionary.
Wrong values for loglikelihood dictionary. Please check your implementation for the loglikelihood dictionary.
12 Tests passed
3 Tests failed
Any additional guidance you could provide would be much appreciated. I appear to be stuck.
Please show us the actual output you get from running the tests for train_naive_bayes
, as I did on this other thread. The most common mistake here by far is just adding 1 for every instance of a word: what is intended is that you add the relevant value from the freqs
dictionary for the appropriate sentiment.
Hi @paulinpaloalto,
The out put was pasted in above but I am pasting here again for reference.
OUTPUT:
Wrong values for loglikelihood dictionary. Please check your implementation for the loglikelihood dictionary.
Wrong values for loglikelihood dictionary. Please check your implementation for the loglikelihood dictionary.
Wrong values for loglikelihood dictionary. Please check your implementation for the loglikelihood dictionary.
12 Tests passed
3 Tests failed
I read your post from before and still think it looks fine to me. I am adding 1 to the freq_pos/freq_neg variable in the numerator per the formula. This has been derived by looking up the values in the freqs dictionary for the word in both the positive and negative cases respectively. What should I try next or what is your suggestion?
Yes, I saw that. Sorry, I meant the previous execution cell. I added some print statements to my code and this is what I see from the previous test cell:
V: 9165, V_pos: 5804, V_neg: 5632, D: 8000, D_pos: 4000, D_neg: 4000, N_pos: 27547, N_neg: 27152
freq_pos for lawnmow = 1
freq_neg for lawnmow = 0
loglikelihood for lawnmow = 0.6823294546700677
freq_pos for smile = 47
freq_neg for smile = 9
loglikelihood for smile = 1.5577981920239676
0.0
9165
It would be worth seeing your numbers for “smile”.
Hi @paulinpaloalto,
Thank you for your help. Having the values for comparison really helped. I get what you were saying now. I missed the wording in the following comment: "Increment the number of positive words by the count for this (word, label) pair. I fixed that and now my test cases pass.
That’s great to hear that you found the solution based on those hints. Onward!