Skip to content

Commit

Permalink
test_explainer: Adapt to latest Orange
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Jan 6, 2025
1 parent 5cd9115 commit 4df22bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion orangecontrib/explain/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def dummy_fit(*_, **__):
model.fit_ = dummy_fit
if model.domain.class_var.is_discrete:
model._estimator_type = "classifier"
model.classes_ = model.domain.class_var.values
model.classes_ = np.array(model.domain.class_var.values)
else:
model._estimator_type = "regressor"

Expand Down
15 changes: 9 additions & 6 deletions orangecontrib/explain/tests/test_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import unittest

import numpy as np
from numpy.testing import assert_array_equal
from Orange.classification import (
LogisticRegressionLearner,
RandomForestLearner,
Expand All @@ -11,6 +10,10 @@
TreeLearner,
ThresholdLearner,
)
try:
from Orange.classification import ScoringSheetLearner
except :
ScoringSheetLearner = None
from Orange.data import Table, Domain, ContinuousVariable
from Orange.regression import LinearRegressionLearner, CurveFitLearner
from Orange.tests import test_regression, test_classification
Expand Down Expand Up @@ -206,7 +209,7 @@ def test_gradient_boosting_shape(self):
)
self.assertEqual(len(shap_values), 2)
self.assertEqual(len(base_value), 2)
assert_array_equal(-shap_values[0], shap_values[1])
np.testing.assert_array_almost_equal(-shap_values[0], shap_values[1])

learner = GBLearner()
model = learner(self.hearth_disease)
Expand All @@ -215,7 +218,7 @@ def test_gradient_boosting_shape(self):
)
self.assertEqual(len(shap_values), 2)
self.assertEqual(len(base_value), 2)
assert_array_equal(-shap_values[0], shap_values[1])
np.testing.assert_array_almost_equal(-shap_values[0], shap_values[1])

learner = XGBRFLearner()
model = learner(self.hearth_disease)
Expand All @@ -224,7 +227,7 @@ def test_gradient_boosting_shape(self):
)
self.assertEqual(len(shap_values), 2)
self.assertEqual(len(base_value), 2)
assert_array_equal(-shap_values[0], shap_values[1])
np.testing.assert_array_almost_equal(-shap_values[0], shap_values[1])

@unittest.skipIf(XGBLearner is None, "Missing 'xgboost' package")
def test_remove_workaround(self):
Expand Down Expand Up @@ -253,8 +256,8 @@ def test_all_classifiers(self):
""" Test explanation for all classifiers """
for learner in test_classification.all_learners():
with self.subTest(learner):
if learner == ThresholdLearner:
# ThresholdLearner require binary class
if learner in (ThresholdLearner, ScoringSheetLearner):
# ThresholdLearner and ScoringSheetLearner require binary class
continue
kwargs = {}
if "base_learner" in inspect.signature(learner).parameters:
Expand Down

0 comments on commit 4df22bd

Please sign in to comment.