Ejemplo n.º 1
0
    def apply(self):
        learner = mean.MeanLearner(preprocessors=self.preprocessors)
        learner.name = self.learner_name
        if self.data is not None:
            predictor = learner(self.data)
            predictor.name = learner.name
        else:
            predictor = None

        self.send("Learner", learner)
        self.send("Predictor", predictor)
Ejemplo n.º 2
0
    def test_mean(self):
        nrows = 1000
        ncols = 10
        x = np.random.random_integers(1, 3, (nrows, ncols))
        y = np.random.random_integers(0, 4, (nrows, 1)) / 3.0
        t = data.Table(x, y)
        learn = mean_.MeanLearner()
        clf = learn(t)

        true_mean = np.average(y)
        x2 = np.random.random_integers(1, 3, (nrows, ncols))
        y2 = clf(x2)
        self.assertTrue(np.allclose(y2, true_mean))
Ejemplo n.º 3
0
    def test_weights(self):
        nrows = 100
        ncols = 10
        x = np.random.random_integers(1, 3, (nrows, ncols))
        y = np.random.random_integers(0, 4, (nrows, 1)) / 3.0
        heavy = 1
        w = ((y == heavy) * 123 + 1.0) / 124.0
        t = data.Table(x, y, W=w)
        learn = mean_.MeanLearner()
        clf = learn(t)

        expected_mean = np.average(y, weights=w)
        x2 = np.random.random_integers(1, 3, (nrows, ncols))
        y2 = clf(x2)
        self.assertTrue(np.allclose(y2, expected_mean))
Ejemplo n.º 4
0
 def test_discrete(self):
     iris = data.Table('iris')
     learn = mean_.MeanLearner()
     self.assertRaises(ValueError, learn, iris)
Ejemplo n.º 5
0
 def test_empty(self):
     autompg = data.Table('auto-mpg')
     learn = mean_.MeanLearner()
     clf = learn(autompg[:0])
     y = clf(autompg[0])
     self.assertTrue(y == 0)