Skip to content

Commit

Permalink
Confusion matrix: fix selected_learner setting
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Aug 26, 2016
1 parent fc840a7 commit 8a492d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
30 changes: 14 additions & 16 deletions Orange/widgets/evaluate/owconfusionmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class OWConfusionMatrix(widget.OWWidget):

settingsHandler = settings.ClassValuesContextHandler()

selected_learner = settings.Setting(0)
selected_learner = settings.Setting([0], schema_only=True)
selection = settings.ContextSetting(set())
selected_quantity = settings.Setting(0)
append_predictions = settings.Setting(True)
Expand All @@ -101,8 +101,6 @@ class OWConfusionMatrix(widget.OWWidget):

def __init__(self):
super().__init__()
if isinstance(self.selected_learner, list):
self.selected_learner = (self.selected_learner + [0])[0]

self.data = None
self.results = None
Expand Down Expand Up @@ -214,7 +212,7 @@ def _init_table(self, nclasses):
def set_results(self, results):
"""Set the input results."""

prev_sel_learner = self.selected_learner
prev_sel_learner = self.selected_learner.copy()
self.clear()
self.warning()
self.closeContext()
Expand Down Expand Up @@ -252,11 +250,11 @@ def set_results(self, results):

self._init_table(len(class_values))
self.openContext(data.domain.class_var)
if prev_sel_learner is None or \
prev_sel_learner >= len(self.learners):
self.selected_learner = 0
print("ZZZ", prev_sel_learner)
if not prev_sel_learner or prev_sel_learner[0] >= len(self.learners):
self.selected_learner[:] = [0]
else:
self.selected_learner = prev_sel_learner
self.selected_learner[:] = prev_sel_learner
self._update()
self._set_selection()
self.unconditional_commit()
Expand Down Expand Up @@ -319,12 +317,12 @@ def cell_clicked(self, model_index):
def commit(self):
"""Output data instances corresponding to selected cells"""
if self.results is not None and self.data is not None \
and self.selected_learner is not None:
and self.selected_learner:
indices = self.tableview.selectedIndexes()
indices = {(ind.row() - 2, ind.column() - 2) for ind in indices}
actual = self.results.actual
learner_name = self.learners[self.selected_learner]
predicted = self.results.predicted[self.selected_learner]
learner_name = self.learners[self.selected_learner[0]]
predicted = self.results.predicted[self.selected_learner[0]]
selected = [i for i, t in enumerate(zip(actual, predicted))
if t in indices]
row_indices = self.results.row_indices[selected]
Expand All @@ -344,7 +342,7 @@ def commit(self):

if self.append_probabilities and \
self.results.probabilities is not None:
probs = self.results.probabilities[self.selected_learner,
probs = self.results.probabilities[self.selected_learner[0],
selected]
extra.append(numpy.array(probs, dtype=object))
pvars = [Orange.data.ContinuousVariable("p({})".format(value))
Expand Down Expand Up @@ -395,8 +393,8 @@ def _isinvalid(x):
return isnan(x) or isinf(x)

# Update the displayed confusion matrix
if self.results is not None and self.selected_learner is not None:
cmatrix = confusion_matrix(self.results, self.selected_learner)
if self.results is not None and self.selected_learner:
cmatrix = confusion_matrix(self.results, self.selected_learner[0])
colsum = cmatrix.sum(axis=0)
rowsum = cmatrix.sum(axis=1)
n = len(cmatrix)
Expand Down Expand Up @@ -459,10 +457,10 @@ def _sum_item(value, border=""):

def send_report(self):
"""Send report"""
if self.results is not None and self.selected_learner is not None:
if self.results is not None and self.selected_learner:
self.report_table(
"Confusion matrix for {} (showing {})".
format(self.learners[self.selected_learner],
format(self.learners[self.selected_learner[0]],
self.quantities[self.selected_quantity].lower()),
self.tableview)

Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,7 @@ class ControlledList(list):
selection in the list box.
"""
def __init__(self, content, listBox=None):
super().__init__(content)
super().__init__(content if content is not None else [])
self.listBox = listBox

def __reduce__(self):
Expand Down

0 comments on commit 8a492d7

Please sign in to comment.