关于使用Keras进行LSTM时间序列预测的参数问题
现在有一组时间序列数据,每个时间点的features为7,想通过前三组时间序列数据预测后两组,于是我把数据reshape成如下的鬼样子:
train_X(43796, 3, 7)
[[[0.12977867 0.35294122 0.24590163 … 0.00229001 0. 0. ]
[0.14889336 0.36764708 0.24590163 … 0.00381099 0. 0. ]
[0.15995975 0.4264706 0.22950819 … 0.00533197 0. 0. ]]
[[0.14889336 0.36764708 0.24590163 … 0.00381099 0. 0. ]
[0.15995975 0.4264706 0.22950819 … 0.00533197 0. 0. ]
[0.18209255 0.48529413 0.22950819 … 0.00839101 0.03703704 0. ]]
[[0.15995975 0.4264706 0.22950819 … 0.00533197 0. 0. ]
[0.18209255 0.48529413 0.22950819 … 0.00839101 0.03703704 0. ]
[0.13883299 0.48529413 0.22950819 … 0.00991199 0.07407407 0. ]]
…
train_y(43796, 2, 7)
[[[0.18209255 0.48529413 0.22950819 … 0.00839101 0.03703704 0. ]
[0.13883299 0.48529413 0.22950819 … 0.00991199 0.07407407 0. ]]
[[0.13883299 0.48529413 0.22950819 … 0.00991199 0.07407407 0. ]
[0.10965794 0.48529413 0.21311474 … 0.01143297 0.11111111 0. ]]
[[0.10965794 0.48529413 0.21311474 … 0.01143297 0.11111111 0. ]
[0.1056338 0.48529413 0.21311474 … 0.01449201 0.14814815 0. ]]
…
好的,我觉得没什么问题啊,但是天要搞我,LSTM模型如下:
# design network
model = Sequential()
model.add(LSTM(50,input_shape=(train_X.shape[1], train_X.shape[2]),return_sequences=True))
model.add(Dense(train_y.shape[2]))
model.summary()
model.compile(loss='mae', optimizer='adam')
# fit network
# history = model.fit(train_X, train_y, epochs=50, batch_size=1, validation_data=(test_X, test_y), verbose=2, shuffle=False)
history = model.fit(train_X, train_y, epochs=50, batch_size=72, verbose=2, shuffle=False)
求问这里面的参数到底怎么写
model.add(LSTM(50,input_shape=(train_X.shape[1], train_X.shape[2]),return_sequences=True))
model.add(Dense(train_y.shape[2]))
因为现在跑的话都是这个错误
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_51 (LSTM) (None, 3, 50) 11600
_________________________________________________________________
dense_47 (Dense) (None, 3, 7) 357
=================================================================
Total params: 11,957
Trainable params: 11,957
Non-trainable params: 0
_________________________________________________________________
ValueError: Error when checking target: expected dense_47 to have shape (3, 7) but got array with shape (2, 7)
我想要的是(3,7)输入预测出(2,7)输出