Skip to content

Commit

Permalink
Fix shap_values compatibility with shap>=0.43.0 by adjusting check_ad…
Browse files Browse the repository at this point in the history
…ditivity parameter handling for TreeExplainer

Signed-off-by: Jacob Reinhold <[email protected]>
  • Loading branch information
jcreinhold committed Apr 4, 2024
1 parent 6219695 commit 9c4fb8d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions econml/_shap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""

import inspect
import shap
from collections import defaultdict
import numpy as np
Expand Down Expand Up @@ -161,7 +162,7 @@ def _shap_explain_model_cate(cme_model, models, X, d_t, d_y, featurizer=None, fe
output_names=output_names_,
input_names=input_names_,
background_samples=background_samples)
if explainer.__class__.__name__ == "Tree":
if "check_additivity" in inspect.signature(explainer).parameters:
shap_out = explainer(F, check_additivity=False)
else:
shap_out = explainer(F)
Expand Down Expand Up @@ -340,7 +341,7 @@ def _shap_explain_multitask_model_cate(cme_model, multitask_model_cate, X, d_t,
input_names=input_names_,
background_samples=background_samples)

if explainer.__class__.__name__ == "Tree":
if "check_additivity" in inspect.signature(explainer).parameters:
shap_out = explainer(F, check_additivity=False)
else:
shap_out = explainer(F)
Expand Down

0 comments on commit 9c4fb8d

Please sign in to comment.