예제 #1
0
 def test_chi2(self):
     nrows, ncols = 500, 5
     X = np.random.randint(4, size=(nrows, ncols))
     y = 10 + (-3 * X[:, 1] + X[:, 3]) // 2
     data = preprocess.DiscretizeTable(Table(X, y))
     scorer = score.Chi2()
     sc = [scorer(a, data) for a in range(ncols)]
     self.assertTrue(np.argmax(sc) == 1)
예제 #2
0
    def test_wrong_class_type(self):
        scorers = [score.Gini(), score.InfoGain(), score.GainRatio()]
        for scorer in scorers:
            with self.assertRaises(ValueError):
                scorer(0, self.housing)

        with self.assertRaises(ValueError):
            score.Chi2(2, self.housing)
        with self.assertRaises(ValueError):
            score.ANOVA(2, self.housing)
        score.UnivariateLinearRegression(2, self.housing)
예제 #3
0
 def test_chi2(self):
     nrows, ncols = 500, 5
     X = np.random.randint(4, size=(nrows, ncols))
     y = 10 + (-3 * X[:, 1] + X[:, 3]) // 2
     domain = Domain.from_numpy(X, y)
     domain = Domain(domain.attributes,
                     DiscreteVariable('c', values=np.unique(y)))
     table = Table(domain, X, y)
     data = preprocess.Discretize()(table)
     scorer = score.Chi2()
     sc = [scorer(data, a) for a in range(ncols)]
     self.assertTrue(np.argmax(sc) == 1)