Python Keras LSTM:使用形状的特征重要性条形图
我正在为时间序列预测做一个LSTM。现在我想了解,哪些特性对输出影响最大,哪些不重要。目标是类似于在pycharm中使用matplotlib的条形图(参考:): 这是我的模型:Python Keras LSTM:使用形状的特征重要性条形图,python,tensorflow,keras,deep-learning,shap,Python,Tensorflow,Keras,Deep Learning,Shap,我正在为时间序列预测做一个LSTM。现在我想了解,哪些特性对输出影响最大,哪些不重要。目标是类似于在pycharm中使用matplotlib的条形图(参考:): 这是我的模型: model = Sequential() model.add(LSTM(num_neurons, activation='relu', input_shape=(train_x.shape[1], train_x.shape[2]), return_sequences=True)) model.add(SeqWeigh
model = Sequential()
model.add(LSTM(num_neurons, activation='relu', input_shape=(train_x.shape[1], train_x.shape[2]), return_sequences=True))
model.add(SeqWeightedAttention())
model.add(Dropout(dropout))
model.add(Dense(1))
adam_opt = keras.optimizers.Adam(lr=adam_lr, beta_1=adam_b1, beta_2=adam_b2, amsgrad=False)
model.compile(loss='mae', optimizer=adam_opt, metrics=[metrics.mae, metrics.mape, metrics.mse])
history = model.fit(train_x, train_y, epochs=n_epoch, batch_size=batch_size, validation_data=(val_x, val_y), verbose=2, shuffle=False, callbacks=[early_stop, checkpoint])
shap.initjs()
background = train_x[np.random.choice(train_x.shape[0], 100, replace=False)]
explainer = shap.DeepExplainer(model, background)
shap_values = explainer.shap_values(val_x)
shap.summary_plot(shap_values, train_x, plot_type="bar", matplotlib=True)
plt.show()
我在计算shap_值(shap_值=…)时遇到以下错误:
有什么想法吗?提前谢谢 如果没有完整的代码或数据,很难重现这个错误。你能把这两个问题都发到我们可以帮助你的地方吗?
ValueError: Dimension 2 in both shapes must be equal, but are 20 and 1. Shapes are [?,3,20] and [?,?,1]. for 'gradients/seq_weighted_attention_1/mul_grad/Select_1' (op: 'Select') with input shapes: [?,?,1], [?,3,20], [?,3,20].