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

查看:346
本文介绍了如何使用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.

我正在使用张量流和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并没有显示批量大于1的示例.我想在您的情况下,可以将具有状态LSTM的四个批处理大小与以下数据(写为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_sizebatch_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天全站免登陆