Skip to content

Commit

Permalink
DataSampler: Fix Bootstrap signature
Browse files Browse the repository at this point in the history
  • Loading branch information
astaric committed Jan 25, 2017
1 parent 4dad547 commit 49f5b26
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Orange/widgets/data/owdatasampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,14 @@ def __init__(self, size=0, random_state=None):
self.size = size
self.random_state = random_state

def __call__(self):
def __call__(self, table=None):
"""Bootstrap indices
Args:
table: Not used (but part of the signature)
Returns:
tuple (out_of_sample, sample) indices
"""
rgen = np.random.RandomState(self.random_state)
sample = rgen.randint(0, self.size, self.size)
sample.sort() # not needed for the code below, just for the user
Expand Down
22 changes: 21 additions & 1 deletion Orange/widgets/data/tests/test_owdatasampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,3 +33,23 @@ def test_stratified_on_unbalanced_data(self):
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)
in_sample = set(self.get_output("Data Sample").ids)
in_remaining = set(self.get_output("Remaining Data").ids)

self.assertEqual(len(in_sample | in_remaining), len(in_input))
self.assertEqual(len(in_sample & in_remaining), 0)
self.assertGreater(len(in_sample), 0)
# The following assert has a really high probability of being true:
# 1-(1/150*2/150*...*145/150) ~= 1-2e-64
self.assertGreater(len(in_remaining), 0)

def select_sampling_type(self, sampling_type):
buttons = self.widget.controls.sampling_type.group.buttons()
buttons[sampling_type].click()

0 comments on commit 49f5b26

Please sign in to comment.