Python Forum
Using SHAP Library for my LSTM model - "Attribute Error"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using SHAP Library for my LSTM model - "Attribute Error"
#1
We used Keras to build our LSTM model as follows:

import keras
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM

#make LSTM model architecture
model2 = Sequential()
model2.add(LSTM(100, return_sequences = True))
model2.add(LSTM(50, return_sequences = True))
model2.add(LSTM(10))
model2.add(Dense(1))
model2.compile(loss='mae', optimizer='adam')
The model builds, trains and predicts successfully but we face the following error when we use SHAP on the LSTM model:
"Attribute Error": 'Deep' object has no attribute 'masker'

The following is how we tried to use SHAP:
import shap
explainer  = shap.DeepExplainer(model2,x_train_appended)
shap_values = explainer(x_train_appended)


And the following is the error received:

Output:
In [56]: import shap ...: explainer = shap.DeepExplainer(model2, x_train_appended) ...: shap_values = explainer(x_train_appended) WARNING:tensorflow:Layers in a Sequential model should only have a single input tensor, but we receive a <class 'list'> input: [<tf.Tensor: shape=(49586, 1, 23), dtype=float32, numpy= array([[[0.40824828, 0.02564103, 0.03370786, ..., 0.4494382 , 0.43333334, 0.59210527]], [[0. , 0.06410257, 0.05617978, ..., 0.4494382 , 0.43333334, 0.59210527]], [[0.5400617 , 0.06410257, 0.06741573, ..., 0.4494382 , 0.43333334, 0.59210527]], ..., [[0.5400617 , 0.01282051, 0.05617978, ..., 0.07865169, 0.01111111, 0.05263158]], [[0. , 0.02564103, 0.05617978, ..., 0.07865169, 0.01111111, 0.05263158]], [[0. , 0.02564103, 0.05617978, ..., 0.07865169, 0.01111111, 0.05263158]]], dtype=float32)>] Consider rewriting this model with the Functional API. Traceback (most recent call last): File "", line 3, in shap_values = explainer(x_train_appended) File "/home/kiton/.local/lib/python3.8/site-packages/shap/explainers/_explainer.py", line 207, in call if issubclass(type(self.masker), maskers.OutputComposite) and len(args)==2: AttributeError: 'Deep' object has no attribute 'masker'
Did anyone run into a similar issue when using SHAP Deep Explainer? Am I doing something wrong here? Any feedback is appreciated. Thanks a lot for your time and help in advance!
Reply


Messages In This Thread
Using SHAP Library for my LSTM model - "Attribute Error" - by vatsalmtailor - Jul-13-2022, 04:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to solve this error "Exceeded 30 redirects" while using "nsepy" library PranayShah 1 414 Apr-28-2024, 02:44 PM
Last Post: Larz60+
  error "list object has no attribute transpose()" usercat123 4 4,429 Jan-28-2022, 12:01 PM
Last Post: usercat123
  Attribute Error Raiden_Arctica 4 4,257 Mar-13-2021, 11:09 AM
Last Post: Raiden_Arctica
  LSTM Model accuracy caps and I can't improve it celinafregoso99 1 2,055 Dec-19-2020, 01:29 PM
Last Post: jefsummers
  Attribute error in Dataframes deshanish 1 2,485 Jul-15-2020, 08:38 AM
Last Post: snippsat
  Attribute error - Sympy VictorG8 1 5,154 Apr-09-2020, 06:03 PM
Last Post: snippsat
  NLTK Download Attribute error laila1a 1 8,793 Jan-27-2019, 12:03 AM
Last Post: Larz60+
  arima model error in python wissam1974 0 4,290 Jan-23-2019, 09:37 AM
Last Post: wissam1974
  [split] np.arrange error - no attribute gyan 2 7,134 Aug-19-2018, 05:38 PM
Last Post: micseydel
  Attribute Error while using tensor flow pratheep 2 6,694 Mar-16-2018, 10:50 AM
Last Post: pratheep

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020