title: What is wrong with the following code snippet?
body: <p>I'm currently trying out some of the code from the book called, "Programming Collective Intelligence", building a document classifier and I ran into this error cause by <code>docclass.py</code>. Can anyone tell me how to debug such problems?</p>
  
  <pre><code>def __init__(self,getfeatures,filename=None):
      self.fc={}
      self.cc={}
      self.getfeatures=getfeatures
  def incf(self,f,cat):
      self.fc.setdefault(f,{})
      self.fc.setdefault(cat,0)
      self.fc[f][cat]+=1
  def incc(self,cat):
      self.cc.setdefault(cat,0)
      self.cc[cat]+=1
  def train(self,item,cat):
      features=self.getfeatures(item)
      for f in features:
          self.incf(f,cat)
      self.incc(cat)
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <pre><code>&gt;&gt;&gt; import docclass
  &gt;&gt;&gt; c1=docclass.classifier(docclass.getwords)
  &gt;&gt;&gt; c1.train('the quick brown fox jumps over the lazy dog','good')
  
  Traceback (most recent call last):
    File "&lt;pyshell#32&gt;", line 1, in &lt;module&gt;
      c1.train('the quick brown fox jumps over the lazy dog','good')
    File "docclass.py", line 36, in train
      self.incf(f,cat)
    File "docclass.py", line 17, in incf
      self.fc[f][cat]+=1
  KeyError: 'good'
  </code></pre>