C1_W1_Assignment - Natural Language Processing with Classification and Vector Spaces

Part 2: Extracting the features: I’m getting a keyError on the frequency for negative label 0 for the word ‘followfriday’. That is because the dictionary of frequencies ‘freqs’ does not have this pair:(‘followfriday’, 0.0).


To solve this I created an if that assigns 0 to that frequency, but the frequencies still do not match.

It is a mistake to assume that every combination of word and sentiment exists in the freqs dictionary. Some words may only have a positive or negative entry. So your logic here needs to take that into account. There are several ways to do that: you can use “if” statements or you can use the “get()” method on the freqs dictionary. If you are not familiar with that, try googling “python dictionary get method”. Using “get()” is the cleanest way to handle this, since it gives you an easy way to add 0 to the cumulative count when the combination is not found.

3 Likes

Hi,
You may need to use get() method applied to freqs.

1 Like