Пример #1
0
 def testCatCount(self):
     c = Classifier(getwords)
     c.incc("Bad")
     c.incc("Bad")
     c.incc("Good")
     self.assertEqual(c.catcount("Good"), 1)
     self.assertEqual(c.catcount("Bad"), 2)
Пример #2
0
 def testWeightedProb(self):
     c = Classifier(getwords)
     c.incc("Good")
     c.incf("hello", "Good")
     c.incc("Good")
     c.incf("world", "Good")
     c.incc("Good")
     c.incf("world", "Good")
     c.incc("Bad")
     c.incf("world", "Bad")
     self.assertEqual(c.weightedprob("world", "Good"), 5.0/8.0)
     self.assertEqual(c.weightedprob("wurst", "Good"), 0.5)
Пример #3
0
 def testIncC(self):
     c = Classifier(getwords)
     c.incc("Bad")
     self.assertEqual(c.cc["Bad"], 1)
     c.incc("Bad")
     self.assertEqual(c.cc["Bad"], 2)
     c.incc("Good")
     self.assertEqual(c.cc["Good"], 1)
Пример #4
0
 def testFProb(self):
     c = Classifier(getwords)
     c.incc("Good")
     c.incf("hello", "Good")
     c.incc("Good")
     c.incf("world", "Good")
     c.incc("Good")
     c.incf("world", "Good")
     self.assertEqual(c.fprob("world", "Good"), 2.0/3.0)
Пример #5
0
    def testProb(self):
        c = Classifier(getwords)

        # training
        c.incc("Good")
        c.incf("hello", "Good")
        c.incc("Good")
        c.incf("world", "Good")
        c.incc("Good")
        c.incf("world", "Good")
        c.incc("Bad")
        c.incf("world", "Bad")

        # classify new document
        item = "world world wurst Wurst wurst world"

        self.assertEqual(c.prob(item, "Good"), 0.234375)
Пример #6
0
 def testTotalCount(self):
     c = Classifier(getwords)
     c.incc("Bad")
     c.incc("Bad")
     c.incc("Good")
     self.assertEqual(c.totalcount(), 3)