From e0c7031a4a4ad0873a0504a4418f682423d72d19 Mon Sep 17 00:00:00 2001 From: janezd Date: Fri, 26 Aug 2016 11:42:20 +0200 Subject: [PATCH] Confusion matrix: fix selected_learner setting --- Orange/widgets/evaluate/owconfusionmatrix.py | 29 +++++++++----------- Orange/widgets/gui.py | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Orange/widgets/evaluate/owconfusionmatrix.py b/Orange/widgets/evaluate/owconfusionmatrix.py index 47a33316e3f..8ace1b89398 100644 --- a/Orange/widgets/evaluate/owconfusionmatrix.py +++ b/Orange/widgets/evaluate/owconfusionmatrix.py @@ -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) @@ -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 @@ -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 and self.selected_learner[0] self.clear() self.warning() self.closeContext() @@ -252,11 +250,10 @@ 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 + if prev_sel_learner and prev_sel_learner >= 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() @@ -319,12 +316,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] @@ -344,7 +341,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)) @@ -395,8 +392,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) @@ -459,10 +456,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) diff --git a/Orange/widgets/gui.py b/Orange/widgets/gui.py index 9075dd3e097..d844967b325 100644 --- a/Orange/widgets/gui.py +++ b/Orange/widgets/gui.py @@ -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):