Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Orange/widgets/evaluate/owconfusionmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from Orange.widgets import widget, settings, gui
from Orange.widgets.utils.annotated_data import (create_annotated_table,
ANNOTATED_DATA_SIGNAL_NAME)
from Orange.widgets.widget import Msg


def confusion_matrix(res, index):
Expand Down Expand Up @@ -105,6 +106,9 @@ class OWConfusionMatrix(widget.OWWidget):
"data instances",
"click_cell")]

class Error(widget.OWWidget.Error):
no_regression = Msg("Confusion Matrix cannot show regression results.")

def __init__(self):
super().__init__()

Expand Down Expand Up @@ -228,7 +232,10 @@ def set_results(self, results):
data = results.data

if data is not None and not data.domain.has_discrete_class:
self.warning("Confusion Matrix cannot show regression results.")
self.Error.no_regression()
data = results = None
else:
self.Error.no_regression.clear()

self.results = results
self.data = data
Expand Down
17 changes: 16 additions & 1 deletion Orange/widgets/evaluate/tests/test_owconfusionmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from Orange.data import Table
from Orange.classification import NaiveBayesLearner, TreeLearner
from Orange.evaluation.testing import CrossValidation
from Orange.regression import MeanLearner
from Orange.evaluation.testing import CrossValidation, TestOnTrainingData
from Orange.widgets.evaluate.owconfusionmatrix import OWConfusionMatrix
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin

Expand Down Expand Up @@ -54,3 +55,17 @@ def _select_data(self):
self.widget.results.actual, self.widget.results.predicted[0]))
if t in indices]
return self.widget.results.row_indices[selected]

def test_show_error_on_regression(self):
"""On regression data, the widget must show error"""
housing = Table("housing")
results = TestOnTrainingData(housing, [MeanLearner()])
results.data = housing
self.send_signal("Evaluation Results", results)
self.assertTrue(self.widget.Error.no_regression.is_shown())
self.send_signal("Evaluation Results", None)
self.assertFalse(self.widget.Error.no_regression.is_shown())
self.send_signal("Evaluation Results", results)
self.assertTrue(self.widget.Error.no_regression.is_shown())
self.send_signal("Evaluation Results", self.results_1_iris)
self.assertFalse(self.widget.Error.no_regression.is_shown())