From 4df22bda10ab7d539bfb80ac901552542e5b09dd Mon Sep 17 00:00:00 2001 From: Vesna Tanko Date: Mon, 6 Jan 2025 09:26:02 +0100 Subject: [PATCH] test_explainer: Adapt to latest Orange --- orangecontrib/explain/inspection.py | 2 +- orangecontrib/explain/tests/test_explainer.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/orangecontrib/explain/inspection.py b/orangecontrib/explain/inspection.py index 931af07..3af0263 100644 --- a/orangecontrib/explain/inspection.py +++ b/orangecontrib/explain/inspection.py @@ -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" diff --git a/orangecontrib/explain/tests/test_explainer.py b/orangecontrib/explain/tests/test_explainer.py index 77c8700..5968625 100644 --- a/orangecontrib/explain/tests/test_explainer.py +++ b/orangecontrib/explain/tests/test_explainer.py @@ -2,7 +2,6 @@ import unittest import numpy as np -from numpy.testing import assert_array_equal from Orange.classification import ( LogisticRegressionLearner, RandomForestLearner, @@ -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 @@ -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) @@ -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) @@ -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): @@ -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: