首页 > 解决方案 > 多并行输入和多步输出时间序列预测

问题描述

我正在学习使用 LSTM 模型进行时间序列预测。我找到了一个不错的教程https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/ 我正在尝试使用 Stacked LSTM 解决“多并行输入和多步输出”中的问题部分。

数据集如下:

[[ 10 15 25]

[ 20 25 45]

[ 30 35 65]

[ 40 45 85]

[ 50 55 105]

[ 60 65 125]

[ 70 75 145]

[ 80 85 165]

[ 90 95 185]]

任务是使用三个时间序列中每个时间序列的最后三个时间步长作为模型的输入,并预测三个时间序列中每个时间序列的下一个时间步长作为输出。

例如,这是 X 输入:

[[10 15 25]

[20 25 45]

[30 35 65]]

这是 y 输出:

[[ 40 45 85]

[ 50 55 105]]

本教程使用Encoder-Decoder结构,但我想应用类似于以下 Stacked LSTM 示例的 Stacked LSTM 结构。但是我的输出是序列的序列,我不知道如何为密集层选择 n_steps_out。

model = Sequential()
model.add(LSTM(100, activation='relu', return_sequences=True,    input_shape=(n_steps_in, n_features)))
model.add(LSTM(100, activation='relu'))
model.add(Dense(n_steps_out))
model.compile(optimizer='adam', loss='mse')
# fit model
model.fit(X, y, epochs=200, verbose=0)

标签: pythontensorflowkeraslstm

解决方案


因为我看到你使用了 machinelearningmastery,所以我将你引导到相同的地方,使用不同的代码,也许你没有找到它。 https://machinelearningmastery.com/multivariate-time-series-forecasting-lstms-keras/ 基本上对你有帮助的是代码开头的“series_to_supervised”函数。它会创建滞后的数据集,您可以随意考虑想要拥有多少滞后。要么那个,要么这个:https ://github.com/llSourcell/How-to-Predict-Stock-Prices-Easily-Demo/blob/master/lstm.py 在这里,您有一个输出序列的示例。希望能帮助到你。


推荐阅读