def test_adaboost_reg_base_estimator(self): np.random.seed(0) stump_estimator = TreeRegressionLearner(max_depth=1) tree_estimator = TreeRegressionLearner() stump = SklAdaBoostRegressionLearner(base_estimator=stump_estimator) tree = SklAdaBoostRegressionLearner(base_estimator=tree_estimator) results = CrossValidation(self.housing, [stump, tree], k=3) rmse = RMSE(results) self.assertGreaterEqual(rmse[0], rmse[1])
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)
def test_input_learner(self): """Check if base learner properly changes with learner on the input""" max_depth = 2 default_base_est = self.widget.base_estimator self.assertIsInstance(default_base_est, TreeRegressionLearner) self.assertIsNone(default_base_est.params.get("max_depth")) self.send_signal("Learner", TreeRegressionLearner(max_depth=max_depth)) self.assertEqual(self.widget.base_estimator.params.get("max_depth"), max_depth) self.widget.apply_button.button.click() output_base_est = self.get_output("Learner").params.get("base_estimator") self.assertEqual(output_base_est.max_depth, max_depth)
def setUpClass(cls): super().setUpClass() WidgetOutputsTestMixin.init(cls) # Set up for output tests tree = TreeClassificationLearner() cls.model = tree(cls.data) cls.model.instances = cls.data cls.signal_name = "Tree" cls.signal_data = cls.model # Set up for widget tests titanic_data = Table('titanic')[::50] cls.titanic = TreeClassificationLearner(max_depth=1)(titanic_data) cls.titanic.instances = titanic_data housing_data = Table('housing')[:10] cls.housing = TreeRegressionLearner(max_depth=1)(housing_data) cls.housing.instances = housing_data
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])
class OWAdaBoostRegression(owadaboost.OWAdaBoostClassification): name = "AdaBoost" description = "An ensemble meta-algorithm that combines weak learners " \ "and adapts to the 'hardness' of each training sample. " icon = "icons/AdaBoost.svg" priority = 80 LEARNER = SklAdaBoostRegressionLearner inputs = [("Learner", LearnerRegression, "set_base_learner")] losses = ["Linear", "Square", "Exponential"] loss = Setting(0) DEFAULT_BASE_ESTIMATOR = TreeRegressionLearner() def add_specific_parameters(self, box): self.loss_combo = gui.comboBox(box, self, "loss", label="Loss:", orientation=Qt.Horizontal, items=self.losses, callback=self.settings_changed) def create_learner(self): return self.LEARNER(base_estimator=self.base_estimator, n_estimators=self.n_estimators, learning_rate=self.learning_rate, preprocessors=self.preprocessors, loss=self.losses[self.loss].lower()) def get_learner_parameters(self): return (("Base estimator", self.base_estimator), ("Number of estimators", self.n_estimators), ("Loss", self.losses[self.loss].capitalize()))
def test_regression(self): table = Table('housing') learn = TreeRegressionLearner() model = learn(table) pred = model(table) self.assertTrue(np.all(table.Y.flatten() == pred))
def test_get_tree_regression(self): table = Table('housing') learn = TreeRegressionLearner() clf = learn(table) self.assertIsInstance(clf.tree, Tree)