You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用shap.DeepExplainer分析LSTM模型时触发AttributeError错误求助

使用shap.DeepExplainer时遇到AttributeError错误

我在使用shap.DeepExplainer时触发了错误,以下是相关信息:

错误信息

AttributeError: Exception encountered when calling layer "lstm" "                 f"(type LSTM).

'TFDeep' object has no attribute 'between_tensors'

Call arguments received by layer "lstm" "                 f"(type LSTM):
  • inputs=tf.Tensor(shape=(4184, 44, 4), dtype=float32)
  • mask=None
  • training=False
  • initial_state=None

模型构建代码

model = Sequential()

n_neurons = x_train.shape[1] * x_train.shape[2]
print(n_neurons, x_train.shape[1], x_train.shape[2])

model.add(LSTM(n_neurons, return_sequences=False, input_shape=(x_train.shape[1], x_train.shape[2])))
model.add(Dense(1))

model.compile(optimizer='adam',loss='mean_squared_error')


history = model.fit(x_train, y_train, 
                        batch_size=batch_size, 
                        epochs=epochs,shuffle=False,
                        validation_data=(x_test, y_test)
                       )

SHAP调用代码

import shap
# 使用训练数据初始化DeepExplainer,也可以用更少样本
explainer_ = shap.DeepExplainer(model, x_train)
shap_values_ = explainer_.shap_values(x_test)

错误截图

错误截图

内容的提问来源于stack exchange,提问作者Pongthorn Sa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 16:25:09