Ejemplo n.º 1
0
 def test_fcbf(self):
     scorer = FCBF()
     weights = scorer(self.zoo, None)
     found = [
         self.zoo.domain[attr].name
         for attr in reversed(weights.argsort()[-5:])
     ]
     reference = ['legs', 'backbone', 'toothed', 'hair', 'aquatic']
     self.assertEqual(found, reference)
    def _fit(self):
        warnings.simplefilter(action='ignore')
        table = self.data.to_table()
        if self.params["eval_method"] == "relief":
            scores = ReliefF(table, n_iterations=100)
        elif self.params["eval_method"] == "fcbf":
            scores = FCBF(table)
        else:
            scores = RandomForestLearner().score_data(table)[0]

        for attr, score in zip(table.domain.attributes, scores):
            self.feature_importances[attr.name] = score
    def test_fcbf(self):
        scorer = FCBF()
        weights = scorer(self.zoo, None)
        found = [
            self.zoo.domain[attr].name
            for attr in reversed(weights.argsort()[-5:])
        ]
        reference = ['legs', 'milk', 'toothed', 'feathers', 'backbone']
        self.assertEqual(found, reference)

        # GH-1916
        data = Table(
            Domain([ContinuousVariable('1'),
                    ContinuousVariable('2')], DiscreteVariable('target')),
            np.full((2, 2), np.nan), np.r_[0., 1])
        weights = scorer(data, None)
        np.testing.assert_equal(weights, np.nan)
Ejemplo n.º 4
0
    def test_fcbf(self):
        scorer = FCBF()
        weights = scorer(self.zoo, None)
        found = [self.zoo.domain[attr].name for attr in reversed(weights.argsort()[-5:])]
        reference = ['legs', 'milk', 'toothed', 'feathers', 'backbone']
        self.assertEqual(found, reference)

        # GH-1916
        data = Table(Domain([ContinuousVariable('1'), ContinuousVariable('2')],
                            DiscreteVariable('target')),
                     np.full((2, 2), np.nan),
                     np.r_[0., 1])
        with warnings.catch_warnings():
            # these warnings are expected
            warnings.filterwarnings("ignore", "invalid value.*double_scalars")
            warnings.filterwarnings("ignore", "invalid value.*true_divide")

            weights = scorer(data, None)
            np.testing.assert_equal(weights, np.nan)
Ejemplo n.º 5
0
    def test_fcbf(self):
        scorer = FCBF()
        weights = scorer(self.zoo, None)
        found = [
            self.zoo.domain[attr].name
            for attr in reversed(weights.argsort()[-5:])
        ]
        reference = ["legs", "milk", "toothed", "feathers", "backbone"]
        self.assertEqual(found, reference)

        # GH-1916
        data = Table(
            Domain(
                [ContinuousVariable("1"),
                 ContinuousVariable("2")],
                DiscreteVariable("target"),
            ),
            np.full((2, 2), np.nan),
            np.r_[0.0, 1],
        )
        weights = scorer(data, None)
        np.testing.assert_equal(weights, np.nan)