如何基于多类softmax激活函数深度学习模型问题为KernelExplainer重塑数据

问题描述

我的模型是多类LSTM。 我想知道如何使用Shap来帮助解释我的模型。

我发现使用Shap困难,因为我的数据是3维的,并且使用softmax输出是多类的。

(我使用tensorflow 1.15,keras 2.2.4)

Model:

L1units=75

L2units=100

L3units=100

L4units=32

#Model DESIGN

model = Sequential()

model.add(Dense(L1units,activation='relu',input_shape=(1,29)))

model.add(LSTM(L2units,return_sequences=True))

model.add(LSTM(L3units,activation='relu'))

model.add(Masking(mask_value=0))

model.add(Dropout(0.2))

model.add(Dense(L4units,activation='softmax'))

opt = tensorflow.keras.optimizers.Adam(learning_rate=0.0001) 

model.compile(loss='categorical_crossentropy',optimizer=opt,metrics=['accuracy'])
 

X_train.shape (193804,1,29) Y_train.shape (193804,32)

X_test.shape ( 48464 1,29)  Y_test.shape (48464,32)

我尝试了DeepExplainer,因为DeepExplainer可以处理3d数据,但是我没有成功。

出现错误消息-LookupError:渐变注册表没有以下条目:shap_TensorListStack

import shap

explainer=shap.DeepExplainer(model,X_train[:100])
shap_values = explainer.shap_values(X_test[:10])

我知道KernelExplainer可以应用于任何模型,但是所需的输入形状必须是二维的(#samples x #features)。基于此stackoverflow Shap LSTM (Keras,TensorFlow) ValueError: shape mismatch: objects cannot be broadcast to a single shape

我应该如何重塑/展平X_train,X_test以便能够使用KernelExplainer?

还是我可以根据错误以某种方式修复DeepExplainer?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)