Exemplo n.º 1
0
    def test_input_scorer_fitter(self):
        heart_disease = Table('heart_disease')
        self.assertEqual(self.widget.scorers, {})

        model = self.widget.ranksModel

        for fitter, name in ((RandomForestLearner(), 'random forest'),
                             (SGDLearner(), 'sgd')):
            with self.subTest(fitter=fitter),\
                    warnings.catch_warnings():
                warnings.filterwarnings("ignore", ".*", ConvergenceWarning)
                self.send_signal("Scorer", fitter, 1)

                for data in (self.housing, heart_disease):
                    with self.subTest(data=data.name):
                        self.send_signal('Data', data)
                        self.wait_until_finished()
                        scores = [
                            model.data(
                                model.index(row,
                                            model.columnCount() - 1))
                            for row in range(model.rowCount())
                        ]
                        self.assertEqual(len(scores),
                                         len(data.domain.attributes))
                        self.assertFalse(np.isnan(scores).any())

                        last_column = model.headerData(model.columnCount() - 1,
                                                       Qt.Horizontal).lower()
                        self.assertIn(name, last_column)

                self.send_signal("Scorer", None, 1)
                self.assertEqual(self.widget.scorers, {})
Exemplo n.º 2
0
    def test_input_scorer_fitter(self):
        heart_disease = Table("heart_disease")
        self.assertEqual(self.widget.scorers, {})

        model = self.widget.ranksModel

        for fitter, name in (
            (RandomForestLearner(), "random forest"),
            (SGDLearner(), "sgd"),
        ):
            with self.subTest(fitter=fitter):
                self.send_signal("Scorer", fitter, 1)

                for data in (self.housing, heart_disease):
                    with self.subTest(data=data.name):
                        self.send_signal("Data", data)
                        scores = [
                            model.data(
                                model.index(row,
                                            model.columnCount() - 1))
                            for row in range(model.rowCount())
                        ]
                        self.assertEqual(len(scores),
                                         len(data.domain.attributes))
                        self.assertFalse(np.isnan(scores).any())

                        last_column = model.headerData(model.columnCount() - 1,
                                                       Qt.Horizontal).lower()
                        self.assertIn(name, last_column)

                self.send_signal("Scorer", None, 1)
                self.assertEqual(self.widget.scorers, {})