使用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
相关产品推荐
相关产品推荐

