我有一个序列,我想做最简单的 LSTM 来预测序列的其余部分。这意味着我想从仅使用上一步来预测下一个步骤开始,然后添加更多步骤。我也想使用预测值作为输入。所以我相信我想要的是实现许多对多如Understanding Keras LSTMs的答案中提到的。
我已经阅读了有关 stackoverflow 主题的其他问题,但仍然无法使其正常工作。在我的代码中,我使用这里的教程https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/和函数 create_dataset 来创建两个数组,只有一个移位一步。
这是我的代码和我得到的错误。
"Here I'm scaling my data as advised"
scaler = MinMaxScaler(feature_range=(0, 1))
Rot = scaler.fit_transform(Rot)
"I'm creating the model using batch_size=1 but I'm not sure why this is necessary"
batch_size = 1
model = Sequential()
model.add(LSTM(1,batch_input_shape=(batch_size,1,1),stateful=True,return_sequences=True,input_shape=(None,1)))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
"I want to use only the previous value for now"
look_back = 1
"as len(Rot) = 41000 I'm taking 36000 for training"
train_size = 36000
X,Y = create_dataset(Rot[:train_size,:],look_back)
X = numpy.reshape(X,(X.shape[0], X.shape[1], 1))
Y = numpy.reshape(Y,(X.shape[0], X.shape[1], 1))
And now I train my network as advised by @Daniel Möller.
epochs = 10
for epoch in range(epochs):
model.reset_states()
model.train_on_batch(X,Y)
" And I get this error "
" PartialTensorShape: Incompatible shapes during merge: [35998,1] vs. [1,1]
[[{{node lstm_11/TensorArrayStack/TensorArrayGatherV3}}]]."
你知道为什么我有这样的错误,因为我似乎做了上述主题中的所有事情吗?