예제 #1
0
 def test_regression(self):
     sf = StackedFitter([TreeLearner(), KNNLearner()])
     cv = CrossValidation(k=3, random_state=0)
     results = cv(self.housing[:50], [sf, TreeLearner(), KNNLearner()])
     mse = MSE()(results)
     self.assertLess(mse[0], mse[1])
     self.assertLess(mse[0], mse[2])
예제 #2
0
 def test_NN_model(self):
     results = CrossValidation(self.iris, [self.learner], k=3)
     self.assertGreater(CA(results), 0.90)
     results = CrossValidation(self.housing, [self.learner], k=3)
     mse = MSE()
     res = mse(results)
     self.assertLess(res[0], 35)
예제 #3
0
 def test_KNN_regression(self):
     learners = [KNNRegressionLearner(),
                 KNNRegressionLearner(metric="mahalanobis")]
     cv = CrossValidation(k=3)
     results = cv(self.housing, learners)
     mse = MSE(results)
     self.assertLess(mse[1], mse[0])
예제 #4
0
 def test_NN_regression(self):
     const = ConstantLearner()
     results = CrossValidation(self.housing, [NNRegressionLearner(), const],
                               k=3)
     mse = MSE()
     res = mse(results)
     self.assertLess(res[0], 35)
     self.assertLess(res[0], res[1])
예제 #5
0
 def test_continuous_class(self):
     data = self.housing
     model = RandomForestRegressionLearner(random_state=0)(data)
     res = permutation_feature_importance(model, data, MSE(),
                                          self.n_repeats)
     shape = len(data.domain.attributes), self.n_repeats
     self.assertEqual(res[0].shape, shape)
     self.assertEqual(res[1], [a.name for a in data.domain.attributes])
예제 #6
0
 def test_regression(self):
     sf = StackedFitter([TreeLearner(), KNNLearner()])
     results = CrossValidation(
         self.housing[:50],
         [sf, TreeLearner(), KNNLearner()], k=3)
     mse = MSE(results)
     self.assertLess(mse[0], mse[1])
     self.assertLess(mse[0], mse[2])
예제 #7
0
    def test_wrap_score_reg(self):
        data = self.housing_missing
        model = RandomForestRegressionLearner(random_state=0)(data)
        scorer = _wrap_score(MSE(), _check_model(model, data))

        mocked_model = Mock(wraps=model)
        baseline_score = scorer(mocked_model, data)
        mocked_model.assert_called_once()
        self.assertAlmostEqual(baseline_score, 2, 0)
예제 #8
0
    def test_wrap_score_predict_reg(self):
        data = self.housing
        model = TreeRegressionLearner()(data)
        scorer = _wrap_score(MSE(), _check_model(model, data))

        mocked_model = Mock(wraps=model)
        baseline_score = scorer(mocked_model, data)
        # mocked_model.assert_not_called()
        # mocked_model.predict.assert_called_once()
        self.assertAlmostEqual(baseline_score, 0, 3)
예제 #9
0
    def test_orange_models(self):
        data = self.heart
        n_repeats = self.n_repeats
        model = NaiveBayesLearner()(data)
        res = permutation_feature_importance(model, data, CA(), n_repeats)
        shape = len(data.domain.attributes), n_repeats
        self.assertEqual(res[0].shape, shape)
        self.assertEqual(res[1], [a.name for a in data.domain.attributes])

        data = self.iris
        model = TreeLearner()(data)
        res = permutation_feature_importance(model, data, AUC(), n_repeats)
        shape = len(data.domain.attributes), n_repeats
        self.assertEqual(res[0].shape, shape)
        self.assertEqual(res[1], [a.name for a in data.domain.attributes])

        data = self.housing
        model = TreeRegressionLearner()(data)
        res = permutation_feature_importance(model, data, MSE(), n_repeats)
        shape = len(data.domain.attributes), n_repeats
        self.assertEqual(res[0].shape, (shape))
        self.assertEqual(res[1], [a.name for a in data.domain.attributes])
예제 #10
0
 def test_NN_model(self):
     results = CrossValidation(self.iris, [NNLearner()], k=3)
     self.assertGreater(CA(results), 0.90)
     results = CrossValidation(self.housing, [NNLearner()], k=3)
     scorer = MSE()
     self.assertLess(scorer(results)[0], 35)
예제 #11
0
 def test_NN_regression(self):
     results = CrossValidation(self.housing, [NNRegressionLearner()], k=3)
     scorer = MSE()
     self.assertLess(scorer(results)[0], 35)