Comments (5)
Thanks for reporting @Amirhossein4096 . Would you be so kind and provide an example that reproduces the issue? Your code is not complete since we cannot define the model in it. Would be great if you could trim your code down to the minimal steps needed to produce this bug.
from shap.
I am using same versions of TensorFlow and Shap. With a LSTM model, I've received same error:
AttributeError Traceback (most recent call last)
Cell In[51], line 11
9 background=shap.sample(scaled_train_X,100)
10 # Create the SHAP DeepExplainer using the model and the reshaped background dataset
---> 11 explainer = shap.DeepExplainer(model, background)
13 # Calculate SHAP values for the reshaped test set
14 shap_values = explainer.shap_values(scaled_test_X)
File ~\AppData\Local\anaconda3\Lib\site-packages\shap\explainers_deep_init_.py:90, in DeepExplainer.init(self, model, data, session, learning_phase_flags)
87 super().init(model, masker)
89 if framework == 'tensorflow':
---> 90 self.explainer = TFDeep(model, data, session, learning_phase_flags)
91 elif framework == 'pytorch':
92 self.explainer = PyTorchDeep(model, data)
File ~\AppData\Local\anaconda3\Lib\site-packages\shap\explainers_deep\deep_tf.py:172, in TFDeep.init(self, model, data, session, learning_phase_flags)
170 self.phi_symbolics = [None]
171 else:
--> 172 noutputs = self.model_output.shape.as_list()[1]
173 if noutputs is not None:
174 self.phi_symbolics = [None for i in range(noutputs)]
AttributeError: 'tuple' object has no attribute 'as_list'
from shap.
@NanK77 would you be so kind to share code so that we can reproduce the issue? We need a definition of the data (at best a minimal set of row) and code to construct the model.
from shap.
I'm also running into this issue- I can't really share code that reproduces the issue because I work in health tech, but the inputs to shap.DeepExplainer are a 3 layer model trained in tensorflow:
simple_nn = Sequential()
simple_nn.add(Dense(256, activation='relu', input_shape=(len(self.feature_names),)))
simple_nn.add(Dense(256, activation='relu'))
simple_nn.add(Dropout(0.2))
simple_nn.add(Dense(256, activation='relu'))
simple_nn.add(Dense(1, activation='sigmoid'))
and a dataframe of numerical features with no nans
can someone let me know if they found a workaround for this?
Here's the exact error I'm getting
AttributeError Traceback (most recent call last)
Cell In[60], line 3
1 import shap
----> 3 explainer = shap.DeepExplainer(nn_model, X_train)
4 shap_values = explainer.shap_values(X_test)
File /opt/conda/lib/python3.10/site-packages/shap/explainers/_deep/init.py:84, in DeepExplainer.init(self, model, data, session, learning_phase_flags)
81 framework = 'tensorflow'
83 if framework == 'tensorflow':
---> 84 self.explainer = TFDeep(model, data, session, learning_phase_flags)
85 elif framework == 'pytorch':
86 self.explainer = PyTorchDeep(model, data)
File /opt/conda/lib/python3.10/site-packages/shap/explainers/_deep/deep_tf.py:172, in TFDeep.init(self, model, data, session, learning_phase_flags)
170 self.phi_symbolics = [None]
171 else:
--> 172 noutputs = self.model_output.shape.as_list()[1]
173 if noutputs is not None:
174 self.phi_symbolics = [None for i in range(noutputs)]
AttributeError: 'tuple' object has no attribute 'as_list'
from shap.
Sorry, should have known this before, but we currently do not support tensorflow 2.16 right now. See https://github.com/shap/shap/blob/master/pyproject.toml#L74. Will close this here, since support of tf 2.16 and keras 3 is way more complicated than this here. See the mentioned issue #3672
from shap.
Related Issues (20)
- TypeError: In v0.20, force plot now requires the base value as the first parameter! Try shap.plots.force(explainer.expected_value, shap_values) or for multi-output models try shap.plots.force(explainer.expected_value[0], shap_values[0]). HOT 1
- Key not found with shap.TreeExplainer and XGBRegressor HOT 1
- BUG: Unable to Generate SHAP values for a dataframe containing text data trained on lstm model HOT 2
- BUG: Error with SHAP Partial Dependence Plot: ValueError: DataFrame.dtypes for data must be int, float, bool or category
- ENH: integrated gradients HOT 1
- Support tf 2.16 and keras 3 HOT 4
- BUG: shap.plots.bar(shap_values) TypeError
- BUG: Custom masker offset is not working properly
- BUG: AssertionError, the SHAP explanations do not sum up to the model's output!
- BUG: Background dataset subsampling HOT 4
- BUG: AttributeError: 'tuple' object has no attribute 'as_list' (tensorflow 2.15.0) HOT 2
- [Meta-issue] Release 0.46.0
- [Meta-issue] Increase test coverage
- Unable to generate explanations for predict_proba using treeexplainer HOT 1
- BUG: wrong output information on the web document HOT 2
- BUG: ImportError when using numpy2 HOT 3
- ENH: Possible support of SHAP for exaplaining custom layers constructed from supported layers
- ENH: Add compatibility for Random Forest Quantile Regressor
- Numpy2 Support HOT 4
- BUG: tests/explainers/test_tree.py::TestExplainerXGBoost::test_xgboost_dmatrix_propagation[XGBRFClassifier] failing on macOs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shap.