Skip to content

Commit bdc564d

Browse files
authored
Merge pull request #1667 from janezd/cn2-data-output
[ENH] CN2RuleViewer: Output sample of training data in absence of separate data
2 parents 4d1ea03 + 79510f5 commit bdc564d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Orange/widgets/visualize/owruleviewer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,19 @@ def commit(self):
137137
data_output = None
138138
self._save_selected(actual=True)
139139

140+
data = self.data or self.classifier and self.classifier.instances
140141
if (self.selected is not None and
141-
self.data is not None and
142+
data is not None and
142143
self.classifier is not None and
143-
self.data.domain.attributes ==
144+
data.domain.attributes ==
144145
self.classifier.original_domain.attributes):
145146

146-
status = np.ones(self.data.X.shape[0], dtype=bool)
147+
status = np.ones(data.X.shape[0], dtype=bool)
147148
for i in self.selected:
148149
rule = self.classifier.rule_list[i]
149-
status &= rule.evaluate_data(self.data.X)
150+
status &= rule.evaluate_data(data.X)
150151

151-
data_output = self.data.from_table_rows(
152-
self.data, status.nonzero()[0])
152+
data_output = data.from_table_rows(data, status.nonzero()[0])
153153

154154
self.send(OWRuleViewer.data_output_identifier, data_output)
155155

Orange/widgets/visualize/tests/test_owruleviewer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def setUp(self):
1414
self.titanic = Table('titanic')
1515
self.learner = CN2Learner()
1616
self.classifier = self.learner(self.titanic)
17+
# CN2Learner does not add `instances` attribute to the model, but
18+
# the Rules widget does. We simulate the model we get from the widget.
19+
self.classifier.instances = self.titanic
1720
self.widget = self.create_widget(OWRuleViewer)
1821

1922
def test_set_data(self):

0 commit comments

Comments
 (0)