# fit an LSTM network to training data
def fit_lstm(train, batch_size, nb_epoch, neurons):
X, y = train[:, 0:-1], train[:, -1]
X = X.reshape(X.shape[0], 1, X.shape[1])
model = Sequential()
model.add(LSTM(neurons, batch_input_shape=(batch_size, X.shape[1], X.shape[2]), stateful=True))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
for i in range(nb_epoch):
model.fit(X, y, epochs=1, batch_size=batch_size, verbose=0, shuffle=False)
model.reset_states()
return model
然后我使用此模型进行训练
lstm_model = fit_lstm(train_scaled, 1, 3000, 4)
我遇到了问题
Expected int32, got tf.Variable 'lstm_2_W_i:0' shape=(1, 4) dtype=float32_ref of type 'Variable' instead.
我不知道如何解决它,有人可以帮忙吗?