-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[FIX] OWRandomForest: Fix, refactor and widget tests #1477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,61 @@ | ||
| # Test methods with long descriptive names can omit docstrings | ||
| # pylint: disable=missing-docstring | ||
| from Orange.widgets.classify.owrandomforest import OWRandomForest | ||
| from Orange.widgets.tests.base import WidgetTest, WidgetLearnerTestMixin | ||
| from Orange.widgets.tests.base import (WidgetTest, WidgetLearnerTestMixin, | ||
| GuiToParam) | ||
|
|
||
|
|
||
| class TestOWRandomForest(WidgetTest, WidgetLearnerTestMixin): | ||
| def setUp(self): | ||
| self.widget = self.create_widget(OWRandomForest, | ||
| stored_settings={"auto_apply": False}) | ||
| self.init() | ||
| n_est_spin = self.widget.n_estimators_spin | ||
| max_f_spin = self.widget.max_features_spin[1] | ||
| rs_spin = self.widget.random_state_spin[1] | ||
| max_d_spin = self.widget.max_depth_spin[1] | ||
| min_s_spin = self.widget.min_samples_split_spin[1] | ||
| n_est_min_max = [n_est_spin.minimum() * 10, n_est_spin.minimum()] | ||
| min_s_min_max = [min_s_spin.minimum(), min_s_spin.maximum()] | ||
| self.gui_to_params = [ | ||
| GuiToParam("n_estimators", n_est_spin, lambda x: x.value(), | ||
| lambda i, x: x.setValue(i), n_est_min_max, n_est_min_max), | ||
| GuiToParam("max_features", max_f_spin, lambda x: "auto", | ||
| lambda i, x: x.setValue(i), ["auto"], [0]), | ||
| GuiToParam("random_state", rs_spin, lambda x: None, | ||
| lambda i, x: x.setValue(i), [None], [0]), | ||
| GuiToParam("max_depth", max_d_spin, lambda x: None, | ||
| lambda i, x: x.setValue(i), [None], [0]), | ||
| GuiToParam("min_samples_split", min_s_spin, lambda x: x.value(), | ||
| lambda i, x: x.setValue(i), min_s_min_max, min_s_min_max)] | ||
|
|
||
| def test_parameters_checked(self): | ||
| """Check learner and model for various values of all parameters | ||
| when all properties are checked | ||
| """ | ||
| self.widget.max_features_spin[0].click() | ||
| self.widget.random_state_spin[0].click() | ||
| self.widget.max_depth_spin[0].click() | ||
| for j in range(1, 4): | ||
| el = self.gui_to_params[j] | ||
| el_min_max = [el.gui_el.minimum(), el.gui_el.maximum()] | ||
| self.gui_to_params[j] = GuiToParam( | ||
| el.name, el.gui_el, lambda x: x.value(), | ||
| lambda i, x: x.setValue(i), el_min_max, el_min_max) | ||
| self.test_parameters() | ||
| # FIXME: checkboxes are reset to default, since the widget settings were saved | ||
| self.widget.max_features_spin[0].setCheckState(False) | ||
| self.widget.random_state_spin[0].setCheckState(False) | ||
| self.widget.max_depth_spin[0].setCheckState(False) | ||
|
|
||
| def test_parameters_unchecked(self): | ||
| """Check learner and model for various values of all parameters | ||
| when properties are not checked | ||
| """ | ||
| self.widget.min_samples_split_spin[0].click() | ||
| el = self.gui_to_params[4] | ||
| self.gui_to_params[4] = GuiToParam(el.name, el.gui_el, lambda x: 2, | ||
| lambda i, x: x.setValue(i), [2], [0]) | ||
| self.test_parameters() | ||
| # FIXME: checkboxes are reset to default, since the widget settings were saved | ||
| self.widget.min_samples_split_spin[0].setCheckState(True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this line needed? Each test should get its own instance of a widget with controls already set to default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too, but the settings are probably saved. However, I did not work without it.