Skip to content

Commit

Permalink
Prediction and Test and Score: give warning/error on wrong domain
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Nov 6, 2018
1 parent ea45200 commit 5fa1b6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Orange/widgets/evaluate/owpredictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from Orange.base import Model
from Orange.data import ContinuousVariable, DiscreteVariable, Value
from Orange.data.table import DomainTransformationError
from Orange.widgets import gui, settings
from Orange.widgets.widget import OWWidget, Msg, Input, Output
from Orange.widgets.utils.itemmodels import TableModel
Expand Down Expand Up @@ -265,7 +266,7 @@ def _call_predictors(self):
or numpy.isnan(pred.results[0]).all():
try:
results = self.predict(pred.predictor, self.data)
except ValueError as err:
except (ValueError, DomainTransformationError) as err:
results = "{}: {}".format(pred.predictor.name, err)
self.predictors[inputid] = pred._replace(results=results)

Expand Down
29 changes: 23 additions & 6 deletions Orange/widgets/evaluate/owtestlearners.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from Orange.base import Learner
import Orange.classification
from Orange.data import Table, DiscreteVariable, ContinuousVariable
from Orange.data.table import DomainTransformationError
from Orange.data.filter import HasClass
from Orange.data.sql.table import SqlTable, AUTO_DL_LIMIT
import Orange.evaluation
Expand Down Expand Up @@ -209,6 +210,8 @@ class Error(OWWidget.Error):
memory_error = Msg("Not enough memory.")
no_class_values = Msg("Target variable has no values.")
only_one_class_var_value = Msg("Target variable has only one value.")
test_data_incompatible = Msg(
"Test data may be incompatible with train data.")

class Warning(OWWidget.Warning):
missing_data = \
Expand All @@ -221,6 +224,8 @@ class Warning(OWWidget.Warning):
class Information(OWWidget.Information):
data_sampled = Msg("Train data has been sampled")
test_data_sampled = Msg("Test data has been sampled")
test_data_transformed = Msg(
"Test data has been transformed to match the train data.")

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -551,14 +556,20 @@ def _update_stats_model(self):
name = learner_name(slot.learner)
head = QStandardItem(name)
head.setData(key, Qt.UserRole)
if isinstance(slot.results, Try.Fail):
head.setToolTip(str(slot.results.exception))
results = slot.results
if isinstance(results, Try.Fail):
head.setToolTip(str(results.exception))
head.setText("{} (error)".format(name))
head.setForeground(QtGui.QBrush(Qt.red))
errors.append("{name} failed with error:\n"
"{exc.__class__.__name__}: {exc!s}"
.format(name=name, exc=slot.results.exception))

if isinstance(results.exception, DomainTransformationError) \
and self.resampling == self.TestOnTest:
self.Error.test_data_incompatible()
self.Information.test_data_transformed.clear()
else:
errors.append("{name} failed with error:\n"
"{exc.__class__.__name__}: {exc!s}"
.format(name=name, exc=slot.results.exception)
)
row = [head]

if class_var is not None and class_var.is_discrete and \
Expand Down Expand Up @@ -744,7 +755,13 @@ def __update(self):
self.cancel()

self.Warning.test_data_unused.clear()
self.Error.test_data_incompatible.clear()
self.Warning.test_data_missing.clear()
self.Information.test_data_transformed(
shown=self.resampling == self.TestOnTest
and self.data is not None
and self.test_data is not None
and self.data.domain.attributes != self.test_data.domain.attributes)
self.warning()
self.Error.class_inconsistent.clear()
self.Error.too_many_folds.clear()
Expand Down

0 comments on commit 5fa1b6d

Please sign in to comment.