Giter VIP home page Giter VIP logo

Comments (5)

CloseChoice avatar CloseChoice commented on June 25, 2024

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.

NanK77 avatar NanK77 commented on June 25, 2024

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.

CloseChoice avatar CloseChoice commented on June 25, 2024

@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.

macayla-donegan avatar macayla-donegan commented on June 25, 2024

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.

CloseChoice avatar CloseChoice commented on June 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.