Skip to content

Commit 6800095

Browse files
authored
Fix shap_values compatibility with shap>=0.43.0 by adjusting check_additivity parameter handling for TreeExplainer (#872)
Signed-off-by: Jacob Reinhold <[email protected]>
1 parent 52efc8e commit 6800095

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

econml/_shap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
"""
1414

15+
import inspect
1516
import shap
1617
from collections import defaultdict
1718
import numpy as np
@@ -161,7 +162,7 @@ def _shap_explain_model_cate(cme_model, models, X, d_t, d_y, featurizer=None, fe
161162
output_names=output_names_,
162163
input_names=input_names_,
163164
background_samples=background_samples)
164-
if explainer.__class__.__name__ == "Tree":
165+
if "check_additivity" in inspect.signature(explainer).parameters:
165166
shap_out = explainer(F, check_additivity=False)
166167
else:
167168
shap_out = explainer(F)
@@ -340,7 +341,7 @@ def _shap_explain_multitask_model_cate(cme_model, multitask_model_cate, X, d_t,
340341
input_names=input_names_,
341342
background_samples=background_samples)
342343

343-
if explainer.__class__.__name__ == "Tree":
344+
if "check_additivity" in inspect.signature(explainer).parameters:
344345
shap_out = explainer(F, check_additivity=False)
345346
else:
346347
shap_out = explainer(F)

0 commit comments

Comments
 (0)