python - 多并行输入和多步输出时间序列预测
问题描述
我正在学习使用 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)
解决方案
因为我看到你使用了 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 在这里,您有一个输出序列的示例。希望能帮助到你。
推荐阅读
- python - Kivy:如何根据鼠标移动(on_touch_move)增加和减少计数?
- javascript - 是否有任何 JavaScript 测试框架支持 ES 模块
- mysql - 从所有具有相同前缀的表中选择 *
- r - R动态调用不同的变量
- java - 尝试将 ojdbc7 作为 maven 依赖项安装时出现问题
- css - 编写媒体查询,我不明白为什么它会改变我的 img 宽度而不是高度?
- python - 爬虫代码在 PyCharm 本地运行成功,但在 Notebook 中出现错误
- forms - 在 vuejs 中提交表单数据时出错
- jakarta-ee - 将入站电子邮件数据提取到 J2ee 应用程序中
- docker - 从 Compose 运行时 Docker Jenkins Home (/var/jenkins_home) 文件夹权限问题