NameError: global name 'numbers_t' is not defined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Terry Fernandez
    New Member
    • Apr 2012
    • 1

    NameError: global name 'numbers_t' is not defined

    Can you help me with the NameError?
    Code:
    def addExample(self, klass, words):
        """
         * TODO
         * Train your model on an example document with label klass ('pos' or 'neg') and
         * words, a list of strings.
         * You should store whatever data structures you use for your classifier 
         * in the NaiveBayes class.
         * Returns nothing
        """
        #numbers_t = (0,)*3
        #numbers_t_sum = (0,)*3
        self.count_docs += 1
        for word in words:
           if word not in self.vocab:
                self.vocab.append(word)
    
        if klass == 'pos':
            self.num_pos += 1
            self.docs_pos.append(words)    
        if klass == 'neg':
            self.num_neg += 1
            self.docs_neg.append(words)
        
        for t in self.vocab:
            self.condprob_pos = math.log(numbers_t(self.vocab, self.docs_pos) + 1) - math.log(self.numbers_t_sum(self.vocab, self.docs_pos) + len(self.vocab))
            
        for t in self.vocab:
            self.condprob_neg = math.log(numbers_t(self.vocab, self.docs_neg) + 1) - math.log(self.numbers_t_sum(self.vocab, self.docs_neg) + len(self.vocab))
        
        pass
        
      def numbers_t(self, a, b):
        for t in a:
            for word in b:
                if t == b:
                    result += 1  
        return result
          
      def numbers_t_sum(self, a, b):
        for t in a:
            for word in b:
                if t == b:
                    result += 1
        sum += result
        return sum
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    You did not post the complete error message so there is no way to tell. Perhaps you commented that line
    #numbers_t = (0,)*3 ??

    Comment

    Working...