EconML icon indicating copy to clipboard operation
EconML copied to clipboard

Bug with SHAP library v.0.41

Open vferraz opened this issue 1 year ago • 1 comments

This bug was present in some SHAP plots (such as in the bar plots):

shap.plots.bar(shap_values_game)

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[47], line 1
----> 1 shap.plots.bar(shap_values_game)

File ~/anaconda3/envs/shap_env2/lib/python3.9/site-packages/shap/plots/_bar.py:54, in bar(shap_values, max_display, order, clustering, clustering_cutoff, merge_cohorts, show_data, show)
     51     assert isinstance(shap_values, dict), "You must pass an Explanation object, Cohorts object, or dictionary to bar plot!"
     53 # unpack our list of Explanation objects we need to plot
---> 54 cohort_labels = list(cohorts.keys())
     55 cohort_exps = list(cohorts.values())
     56 for i in range(len(cohort_exps)):

UnboundLocalError: local variable 'cohorts' referenced before assignment

This bug was fixed in the 0.42 release (https://github.com/shap/shap/releases/tag/v0.42.0); however, econml has SHAP<=0.41 as a requirement, so these issues will persist until the requirements for the SHAP version are updated.

vferraz avatar Aug 10 '23 08:08 vferraz

Another reason to upgrade to shap 0.42 is https://github.com/py-why/EconML/issues/807

davidpomerenke avatar Aug 13 '23 08:08 davidpomerenke