-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[FIX] DataSampler: Fix crash when stratifying unbalanced datasets #1952
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ def setUpClass(cls): | |
cls.iris = Table("iris") | ||
|
||
def setUp(self): | ||
self.widget = self.create_widget(OWDataSampler) | ||
self.widget = self.create_widget(OWDataSampler) # type: OWDataSampler | ||
|
||
def test_error_message(self): | ||
""" Check if error message appears and then disappears when | ||
|
@@ -26,3 +26,36 @@ def test_error_message(self): | |
self.assertFalse(self.widget.Error.too_many_folds.is_shown()) | ||
self.send_signal("Data", Table(self.iris.domain)) | ||
self.assertTrue(self.widget.Error.no_data.is_shown()) | ||
|
||
def test_stratified_on_unbalanced_data(self): | ||
unbalanced_data = self.iris[:51] | ||
|
||
self.widget.controls.stratify.setChecked(True) | ||
self.send_signal("Data", unbalanced_data) | ||
self.assertTrue(self.widget.Warning.could_not_stratify.is_shown()) | ||
|
||
def test_bootstrap(self): | ||
self.select_sampling_type(self.widget.Bootstrap) | ||
|
||
self.send_signal("Data", self.iris) | ||
|
||
in_input = set(self.iris.ids) | ||
sample = self.get_output("Data Sample") | ||
in_sample = set(sample.ids) | ||
in_remaining = set(self.get_output("Remaining Data").ids) | ||
|
||
# Bootstrap should sample len(input) instances | ||
self.assertEqual(len(sample), len(self.iris)) | ||
# Sample and remaining should cover all instances, while none | ||
# should be present in both | ||
self.assertEqual(len(in_sample | in_remaining), len(in_input)) | ||
self.assertEqual(len(in_sample & in_remaining), 0) | ||
# Sampling with replacement will always produce at least one distinct | ||
# instance in sample, and at least one instance in remaining with | ||
# high probability (1-(1/150*2/150*...*150/150) ~= 1-2e-64) | ||
self.assertGreater(len(in_sample), 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Third, isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, it is also stated in the comment above: |
||
self.assertGreater(len(in_remaining), 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't you use |
||
|
||
def select_sampling_type(self, sampling_type): | ||
buttons = self.widget.controls.sampling_type.group.buttons() | ||
buttons[sampling_type].click() |
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.
This is cool. It always annoys me, but I never thought of helping PyCharm here...
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 saw this in tests aleš writes :)