Example #1
0
 def test_target_in_attributes(self):
     """
     If target in attributes precision is 1.0.
     """
     self.problem.attributes = [self.target]
     self.this = self.classifier(self.corpus, self.problem)
     prec = evaluation.precision(self.this, self.test_set)
     self.assertEqual(prec, 1.0)
Example #2
0
 def test_target_in_attributes(self):
     """
     If target in attributes precision is 1.0.
     """
     self.problem.attributes = [self.target]
     self.this = self.classifier(self.corpus, self.problem)
     prec = evaluation.precision(self.this, self.test_set)
     self.assertEqual(prec, 1.0)
Example #3
0
    def test_better_than_majority(self):
        d = defaultdict(int)
        for example in self.corpus:
            d[self.target(example)] += 1
        majority = max(d, key=d.get)

        class MockClassifier(object):
            def classify(self, example):
                return majority, 1.0

        mock = MockClassifier()
        mock_prec = evaluation.precision(mock, self.target, self.test_set)
        this_prec = evaluation.precision(self.this, self.target, self.test_set)
        try:
            self.assertGreaterEqual(this_prec, mock_prec)
        except:
            print self.corpus
Example #4
0
    def test_better_than_majority(self):
        d = defaultdict(int)
        for example in self.corpus:
            d[self.target(example)] += 1
        majority = max(d, key=d.get)

        class MockClassifier(object):
            def classify(self, example):
                return majority, 1.0

        mock = MockClassifier()
        mock_prec = evaluation.precision(mock, self.target, self.test_set)
        this_prec = evaluation.precision(self.this, self.target, self.test_set)
        try:
            self.assertGreaterEqual(this_prec, mock_prec)
        except:
            print self.corpus
Example #5
0
 def test_tolerates_empty_attributes(self):
     self.problem.attributes = []
     self.this = self.classifier(self.corpus, self.problem)
     evaluation.precision(self.this, self.test_set)
Example #6
0
 def test_tolerates_empty_attributes(self):
     self.problem.attributes = []
     self.this = self.classifier(self.corpus, self.problem)
     evaluation.precision(self.this, self.test_set)
Example #7
0
 def test_bad_testset(self):
     test = []
     with self.assertRaises(ValueError):
         precision(self.c, test)
Example #8
0
 def test_is_0(self):
     test = [(1, 3, 3), (1, 2, 2)]
     p = precision(self.c, test)
     self.assertEqual(p, 0.0)
Example #9
0
 def test_is_1(self):
     test = [(0, 3, 3), (0, 2, 2)]
     p = precision(self.c, test)
     self.assertEqual(p, 1.0)
Example #10
0
 def test_bad_testset(self):
     test = []
     with self.assertRaises(ValueError):
         precision(self.c, test)
Example #11
0
 def test_is_0(self):
     test = [(1, 3, 3), (1, 2, 2)]
     p = precision(self.c, test)
     self.assertEqual(p, 0.0)
Example #12
0
 def test_is_1(self):
     test = [(0, 3, 3), (0, 2, 2)]
     p = precision(self.c, test)
     self.assertEqual(p, 1.0)