Shap: Shap.plots.bar and shap.plots.waterfall - Are these working currently?

Created on 24 Nov 2020  路  2Comments  路  Source: slundberg/shap

Hi -

Issue# 1

I am following the example plot for for bar and waterfall here but not able to run the code. Can anyone confirm are these deprecated in the latest versions of SHAP.

import xgboost
import shap

# train XGBoost model
X,y = shap.datasets.adult()
model = xgboost.XGBClassifier().fit(X, y)

# compute SHAP values
explainer = shap.Explainer(model, X)
shap_values = explainer(X)

Exception Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/shap/explainers/_linear.py in supports_model_with_masker(model, masker)
268 try:
--> 269 Linear._parse_model(model)
270 except e:

3 frames
/usr/local/lib/python3.6/dist-packages/shap/explainers/_linear.py in _parse_model(model)
255 else:
--> 256 raise Exception("An unknown model type was passed: " + str(type(model)))
257

Exception: An unknown model type was passed:

During handling of the above exception, another exception occurred:

NameError Traceback (most recent call last)
in ()
7
8 # compute SHAP values
----> 9 explainer = shap.Explainer(model, X)
10 shap_values = explainer(X)

/usr/local/lib/python3.6/dist-packages/shap/explainers/_explainer.py in __init__(self, model, masker, link, algorithm, output_names, feature_names, **kwargs)
97
98 # use implementation-aware methods if possible
---> 99 if explainers.Linear.supports_model_with_masker(model, self.masker):
100 algorithm = "linear"
101 elif explainers.Tree.supports_model_with_masker(model, self.masker): # TODO: check for Partition?

/usr/local/lib/python3.6/dist-packages/shap/explainers/_linear.py in supports_model_with_masker(model, masker)
268 try:
269 Linear._parse_model(model)
--> 270 except e:
271 return False
272 return True

NameError: name 'e' is not defined

Issue 2:

When I try to use plots.bar and plots.waterfall with TreeExplainer, I get below error:
shap.plots.bar(shap_values_train)


AssertionError Traceback (most recent call last)
in ()
----> 1 shap.plots.bar(shap_values_train)

/usr/local/lib/python3.6/dist-packages/shap/plots/_bar.py in bar(shap_values, max_display, order, clustering, clustering_cutoff, merge_cohorts, show_data, show)
49 cohorts = shap_values.cohorts
50 else:
---> 51 assert isinstance(shap_values, dict), "You must pass an Explanation object, Cohorts object, or dictionary to bar plot!"
52
53 # unpack our list of Explanation objects we need to plot

AssertionError: You must pass an Explanation object, Cohorts object, or dictionary to bar plot!

Note: I am using Colab

Most helpful comment

Hi, I am not able to run the code either...

Python 3.8.3
Shap version: 0.37.0

I get the same error

All 2 comments

Hi, I am not able to run the code either...

Python 3.8.3
Shap version: 0.37.0

I get the same error

Was this page helpful?
0 / 5 - 0 ratings