How to use the simpleai.machine_learning.evaluation.precision function in simpleai

To help you get started, we’ve selected a few simpleai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simpleai-team / simpleai / tests / machine_learning / test_classifiers.py View on Github external
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):
            target = self.target

            def classify(self, example):
                return majority, 1.0

        mock = MockClassifier()
        mock_prec = evaluation.precision(mock, self.test_set)
        this_prec = evaluation.precision(self.this, self.test_set)
        try:
            self.assertGreaterEqual(this_prec, mock_prec)
        except:
            print self.corpus
github simpleai-team / simpleai / tests / machine_learning / test_classifiers.py View on Github external
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)
github simpleai-team / simpleai / tests / machine_learning / test_evaluation.py View on Github external
def test_is_0(self):
        test = [(1, 3, 3), (1, 2, 2)]
        p = precision(self.c, test)
        self.assertEqual(p, 0.0)
github simpleai-team / simpleai / tests / machine_learning / test_evaluation.py View on Github external
def test_bad_testset(self):
        test = []
        with self.assertRaises(ValueError):
            precision(self.c, test)
github simpleai-team / simpleai / tests / machine_learning / test_evaluation.py View on Github external
def test_is_1(self):
        test = [(0, 3, 3), (0, 2, 2)]
        p = precision(self.c, test)
        self.assertEqual(p, 1.0)
github simpleai-team / simpleai / tests / machine_learning / test_classifiers.py View on Github external
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):
            target = self.target

            def classify(self, example):
                return majority, 1.0

        mock = MockClassifier()
        mock_prec = evaluation.precision(mock, self.test_set)
        this_prec = evaluation.precision(self.this, self.test_set)
        try:
            self.assertGreaterEqual(this_prec, mock_prec)
        except:
            print self.corpus
github simpleai-team / simpleai / tests / machine_learning / test_classifiers.py View on Github external
def test_tolerates_empty_attributes(self):
        self.problem.attributes = []
        self.this = self.classifier(self.corpus, self.problem)
        evaluation.precision(self.this, self.test_set)