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)
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)
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)
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)
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)
def testTotalCount(self): c = Classifier(getwords) c.incc("Bad") c.incc("Bad") c.incc("Good") self.assertEqual(c.totalcount(), 3)