Week1 extract_features function

Hi, I’m getting wrong values when I retrieve frequencies from the ‘frees’ dictionary.
For example:
I use
x[0,1] += freqs[‘word’,1.0]
to retrieve the positive frequencies, and
x[0,2] += freqs[‘word’,0.0]
for the negative ones.
But then in test2 I get the output: [[ 1. 51. 39.]] where I should get [[ 1. 0. 0.]].

I don’t understand what is wrong with my retrials from the frees dict.

should be x[0,1] += freqs.get((word, 1.0), 0)

this will enable you to capture cases where the word is not in either the positive or negative corpus and give it a value of 0.

I hope this helps:)


Thank you. This was very helpful.

Thanks a lot, I was stuck too