如何使用 LSTM 单元训练 RNN 以进行时间序列预测 [英] How to train a RNN with LSTM cells for time series prediction

查看:34
本文介绍了如何使用 LSTM 单元训练 RNN 以进行时间序列预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试构建一个简单的模型来预测时间序列.目标是使用序列训练模型,以便模型能够预测未来值.

I'm currently trying to build a simple model for predicting time series. The goal would be to train the model with a sequence so that the model is able to predict future values.

我正在使用 tensorflow 和 lstm 单元来执行此操作.该模型通过时间截断反向传播进行训练.我的问题是如何构建训练数据.

I'm using tensorflow and lstm cells to do so. The model is trained with truncated backpropagation through time. My question is how to structure the data for training.

例如,假设我们想学习给定的序列:

For example let's assume we want to learn the given sequence:

[1,2,3,4,5,6,7,8,9,10,11,...]

我们为 num_steps=4 展开网络.

选项 1

input data               label     
1,2,3,4                  2,3,4,5
5,6,7,8                  6,7,8,9
9,10,11,12               10,11,12,13
...

选项 2

input data               label     
1,2,3,4                  2,3,4,5
2,3,4,5                  3,4,5,6
3,4,5,6                  4,5,6,7
...

选项 3

input data               label     
1,2,3,4                  5
2,3,4,5                  6
3,4,5,6                  7
...

选项 4

input data               label     
1,2,3,4                  5
5,6,7,8                  9
9,10,11,12               13
...

任何帮助将不胜感激.

推荐答案

在阅读了几篇 LSTM 介绍博客后,例如Jakob Aungiers',选项 3 似乎是无状态 LSTM 的正确选项.

After reading several LSTM introduction blogs e.g. Jakob Aungiers', option 3 seems to be the right one for stateless LSTM.

如果你的 LSTM 需要比 num_steps 更早地记住数据,你可以以有状态的方式进行训练 - 有关 Keras 示例,请参阅 Philippe Remy 的博文Keras 中的有状态 LSTM".但是,Philippe 没有展示批量大小大于 1 的示例.我猜在您的情况下,有状态 LSTM 的批量大小为 4 可以与以下数据一起使用(写为 input -> label):

If your LSTMs need to remember data longer ago than your num_steps, your can train in a stateful way - for a Keras example see Philippe Remy's blog post "Stateful LSTM in Keras". Philippe does not show an example for batch size greater than one, however. I guess that in your case a batch size of four with stateful LSTM could be used with the following data (written as input -> label):

batch #0:
1,2,3,4 -> 5
2,3,4,5 -> 6
3,4,5,6 -> 7
4,5,6,7 -> 8

batch #1:
5,6,7,8 -> 9
6,7,8,9 -> 10
7,8,9,10 -> 11
8,9,10,11 -> 12

batch #2:
9,10,11,12 -> 13
...

由此,例如的状态第 0 批中的第二个样本被正确地重复使用以继续使用第 1 批中的第二个样本进行训练.

By this, the state of e.g. the 2nd sample in batch #0 is correctly reused to continue training with the 2nd sample of batch #1.

这在某种程度上类似于您的选项 4,但是您没有使用那里的所有可用标签.

This is somehow similar to your option 4, however you are not using all available labels there.

更新:

作为 batch_size 等于 num_steps 的建议的扩展,Alexis Huet 对于 batch_sizenum_steps 的除数的情况给出了答案,它可以用于更大的 num_steps.他在他的博客上很好地描述了它.

In extension to my suggestion where batch_size equals the num_steps, Alexis Huet gives an answer for the case of batch_size being a divisor of num_steps, which can be used for larger num_steps. He describes it nicely on his blog.

这篇关于如何使用 LSTM 单元训练 RNN 以进行时间序列预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆