Always getting the below error
KeyError Traceback (most recent call last)
Cell In[87], line 1
----> 1 w1_unittest.test_prob_word_given_class(prob_word_given_class, word_frequency, class_frequency)
File ~/work/w1_unittest.py:146, in test_prob_word_given_class(target, word_frequency, class_frequency)
137 if not np.isclose(output,expected):
138 failed_cases.append(
139 {
140 “name”:test_case[‘name’],
(…)
144
145 )
→ 146 print(f"Wrong value for P({test_case[‘input’][‘word’]} | spam = {test_case[‘input’][‘spam’]}) in {failed_cases[-1][‘name’]}. Expected: {failed_cases[-1][‘expected’]}. Got: {failed_cases[-1][‘got’]}")
147 continue
148 successful_cases+=1
KeyError: ‘spam’
in def get word frequency grade cell, for code statement
If the word is not already in the dictionary, manually add it. Remember that you will start every word count as 1 both in spam and ham
check if you have incorrect dictionary keys. check if your statment is
for word in email, if word not in word_dict.keys( ) (You probably used word_dict)
How can I share the code so that you can review
click on my name and then message. please DM only screenshot of grade cell codes and don’t send notebook.
I have DM the screenshot of the cells.I really appreciate any help you can provide.
abhinav,
you seem to have edited part of codes you werent suppose to. You changed the return arguments
Also you hard coded the path for code I mentions previously.
Get a fresh copy and re-do your assignment, and remember when you do this time assignment, you are only suppose to write codes between ###START AND END CODE HERE### with the instructions already given and do not delete, edit anything outside these markers.
Regards
DP
Thank you for the advice, much appreciated. How to get the Fresh copy?
Your suggestions helped me. Thank you so much