|
2 | 2 | # pylint: disable=missing-docstring |
3 | 3 | from Orange.widgets.regression.owrandomforestregression import \ |
4 | 4 | OWRandomForestRegression |
5 | | -from Orange.widgets.tests.base import WidgetTest, WidgetLearnerTestMixin |
| 5 | +from Orange.widgets.tests.base import (WidgetTest, WidgetLearnerTestMixin, |
| 6 | + GuiToParam) |
6 | 7 |
|
7 | 8 |
|
8 | 9 | class TestOWRandomForestRegression(WidgetTest, WidgetLearnerTestMixin): |
9 | 10 | def setUp(self): |
10 | 11 | self.widget = self.create_widget(OWRandomForestRegression, |
11 | 12 | stored_settings={"auto_apply": False}) |
12 | 13 | self.init() |
| 14 | + n_est_spin = self.widget.n_estimators_spin |
| 15 | + max_f_spin = self.widget.max_features_spin[1] |
| 16 | + rs_spin = self.widget.random_state_spin[1] |
| 17 | + max_d_spin = self.widget.max_depth_spin[1] |
| 18 | + min_s_spin = self.widget.min_samples_split_spin[1] |
| 19 | + n_est_min_max = [n_est_spin.minimum() * 10, n_est_spin.minimum()] |
| 20 | + min_s_min_max = [min_s_spin.minimum(), min_s_spin.maximum()] |
| 21 | + self.gui_to_params = [ |
| 22 | + GuiToParam("n_estimators", n_est_spin, lambda x: x.value(), |
| 23 | + lambda i, x: x.setValue(i), n_est_min_max, n_est_min_max), |
| 24 | + GuiToParam("max_features", max_f_spin, lambda x: "auto", |
| 25 | + lambda i, x: x.setValue(i), ["auto"], [0]), |
| 26 | + GuiToParam("random_state", rs_spin, lambda x: None, |
| 27 | + lambda i, x: x.setValue(i), [None], [0]), |
| 28 | + GuiToParam("max_depth", max_d_spin, lambda x: None, |
| 29 | + lambda i, x: x.setValue(i), [None], [0]), |
| 30 | + GuiToParam("min_samples_split", min_s_spin, lambda x: x.value(), |
| 31 | + lambda i, x: x.setValue(i), min_s_min_max, min_s_min_max)] |
| 32 | + |
| 33 | + def test_parameters_checked(self): |
| 34 | + """Check learner and model for various values of all parameters |
| 35 | + when all properties are checked |
| 36 | + """ |
| 37 | + self.widget.max_features_spin[0].click() |
| 38 | + self.widget.random_state_spin[0].click() |
| 39 | + self.widget.max_depth_spin[0].click() |
| 40 | + for j in range(1, 4): |
| 41 | + el = self.gui_to_params[j] |
| 42 | + el_min_max = [el.gui_el.minimum(), el.gui_el.maximum()] |
| 43 | + self.gui_to_params[j] = GuiToParam( |
| 44 | + el.name, el.gui_el, lambda x: x.value(), |
| 45 | + lambda i, x: x.setValue(i), el_min_max, el_min_max) |
| 46 | + self.test_parameters() |
| 47 | + # FIXME: checkboxes are reset to default, since the widget settings were saved |
| 48 | + self.widget.max_features_spin[0].setCheckState(False) |
| 49 | + self.widget.random_state_spin[0].setCheckState(False) |
| 50 | + self.widget.max_depth_spin[0].setCheckState(False) |
| 51 | + |
| 52 | + def test_parameters_unchecked(self): |
| 53 | + """Check learner and model for various values of all parameters |
| 54 | + when properties are not checked |
| 55 | + """ |
| 56 | + self.widget.min_samples_split_spin[0].click() |
| 57 | + el = self.gui_to_params[4] |
| 58 | + self.gui_to_params[4] = GuiToParam(el.name, el.gui_el, lambda x: 2, |
| 59 | + lambda i, x: x.setValue(i), [2], [0]) |
| 60 | + self.test_parameters() |
| 61 | + # FIXME: checkboxes are reset to default, since the widget settings were saved |
| 62 | + self.widget.min_samples_split_spin[0].setCheckState(True) |
0 commit comments