Skip to content Skip to sidebar Skip to footer

Python Key Error

I'm having a Python Key Error and haven't been able to sort it out. The error that is given is shown below Traceback (most recent call last): File '', line 1, in &

Solution 1:

If you look at all the entries in trainingset.txt, you'll see that all the entries with Without-pay are listed as having <=50k income. As you can see in __init__, the training data is split into two groups:

forrowin data:
              if row[15] ==' >50K':
                    self.greaterThan_data.append(row)
              else:
                    self.lessThan_data.append(row)

Since none of the Without-pay entries have >50k income, none of them go into greaterThan_data.

So when you call...

self.greater_class_prob_dist = self.getCatProbs(self.greaterThan_data,2)

..the resulting dict lacks that key.

Post a Comment for "Python Key Error"