Skip to content

Commit

Permalink
Merge pull request #1667 from janezd/cn2-data-output
Browse files Browse the repository at this point in the history
[ENH] CN2RuleViewer: Output sample of training data in absence of separate data
  • Loading branch information
VesnaT authored Oct 19, 2016
2 parents 4d1ea03 + 79510f5 commit bdc564d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Orange/widgets/visualize/owruleviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ def commit(self):
data_output = None
self._save_selected(actual=True)

data = self.data or self.classifier and self.classifier.instances
if (self.selected is not None and
self.data is not None and
data is not None and
self.classifier is not None and
self.data.domain.attributes ==
data.domain.attributes ==
self.classifier.original_domain.attributes):

status = np.ones(self.data.X.shape[0], dtype=bool)
status = np.ones(data.X.shape[0], dtype=bool)
for i in self.selected:
rule = self.classifier.rule_list[i]
status &= rule.evaluate_data(self.data.X)
status &= rule.evaluate_data(data.X)

data_output = self.data.from_table_rows(
self.data, status.nonzero()[0])
data_output = data.from_table_rows(data, status.nonzero()[0])

self.send(OWRuleViewer.data_output_identifier, data_output)

Expand Down
3 changes: 3 additions & 0 deletions Orange/widgets/visualize/tests/test_owruleviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def setUp(self):
self.titanic = Table('titanic')
self.learner = CN2Learner()
self.classifier = self.learner(self.titanic)
# CN2Learner does not add `instances` attribute to the model, but
# the Rules widget does. We simulate the model we get from the widget.
self.classifier.instances = self.titanic
self.widget = self.create_widget(OWRuleViewer)

def test_set_data(self):
Expand Down

0 comments on commit bdc564d

Please sign in to comment.