Ejemplo n.º 1
0
    def testCN2Learner(self):
        learner = CN2Learner()

        # classic CN2 removes covered learning instances
        self.assertTrue(learner.cover_and_remove ==
                        _RuleLearner.exclusive_cover_and_remove)

        # Entropy measure is used to evaluate found hypotheses
        self.assertTrue(
            type(learner.rule_finder.quality_evaluator) == EntropyEvaluator)

        # test that the learning requirements are relaxed by default
        self.assertTrue(
            learner.rule_finder.general_validator.max_rule_length >= 5)
        self.assertTrue(
            learner.rule_finder.general_validator.min_covered_examples == 1)

        classifier = learner(self.titanic)
        self.assertEqual(classifier.original_domain, self.titanic.domain)

        # all learning instances are covered when limitations do not
        # impose rule length or minimum number of covered examples
        num_covered = np.sum(
            [rule.curr_class_dist for rule in classifier.rule_list])
        self.assertEqual(num_covered, self.titanic.X.shape[0])

        # prediction (matrix-wise, all testing instances at once)
        # test that returned result is of correct size
        predictions = classifier.predict(self.titanic.X)
        self.assertEqual(len(predictions), self.titanic.X.shape[0])
Ejemplo n.º 2
0
 def setUp(self):
     self.titanic = Table('titanic')
     self.learner = CN2Learner()
     self.classifier = self.learner(self.titanic)
     # CN2Learner does not add `instances` attribute to the model, but
     # the Rules widget does. We simulate the model we get from the widget.
     self.classifier.instances = self.titanic
     self.widget = self.create_widget(OWRuleViewer)
Ejemplo n.º 3
0
    def setUpClass(cls):
        super().setUpClass()
        WidgetOutputsTestMixin.init(cls)

        cls.titanic = Table('titanic')
        cls.learner = CN2Learner()
        cls.classifier = cls.learner(cls.titanic)
        # CN2Learner does not add `instances` attribute to the model, but
        # the Rules widget does. We simulate the model we get from the widget.
        cls.classifier.instances = cls.titanic

        cls.signal_name = "Classifier"
        cls.signal_data = cls.classifier
        cls.data = cls.titanic
Ejemplo n.º 4
0
 def setUp(self):
     self.titanic = Table('titanic')
     self.learner = CN2Learner()
     self.classifier = self.learner(self.titanic)
     self.widget = self.create_widget(OWRuleViewer)
Ejemplo n.º 5
0
            textoffset = pw + vmargin * 2
            painter.save()
            baseline = rect.bottom() - textoffset / 2

            text = str(index.data(Qt.DisplayRole))
            option.displayAlignment = Qt.AlignCenter
            text_rect = rect.adjusted(0, 0, 0, -textoffset * 0)
            self.drawDisplay(painter, option, text_rect, text)

            painter.setRenderHint(QPainter.Antialiasing)
            for prop, color in zip(curr_class_dist, self.color_schema):
                if prop == 0:
                    continue
                painter.setPen(QPen(QBrush(color), pw))
                to_x = x + prop * width
                line = QLineF(x, baseline, to_x, baseline)
                painter.drawLine(line)
                x = to_x
            painter.restore()

        painter.restore()


if __name__ == "__main__":  # pragma: no cover
    from Orange.classification import CN2Learner
    data = Table("iris")
    learner = CN2Learner()
    model = learner(data)
    model.instances = data
    WidgetPreview(OWRuleViewer).run(model)