具有keras和多个序列的时间序列预测

编程入门 行业动态 更新时间:2024-10-23 10:32:32
本文介绍了具有keras和多个序列的时间序列预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我了解Keras上的状态LSTM预测示例一个序列.该示例包含一个50k观测值的序列.

I understand the stateful LSTM prediction example in Keras on a single sequence. That example has one sequence of 50k observations.

我的问题:

  • 如果您要训练多个50k观测序列,该怎么办?说一个以不同的值开始/结束并且行为略有不同的人吗?
  • 如何修改示例以增加预测时间步长?
  • LSTM对这种事情有什么好处吗?

完全可复制的示例,具有3个均值回复时间序列并预测20个步骤.

Fully replicable example with 3 mean-reverting time series and predicting 20 steps out.

# generate random data import statsmodels.api as sm import numpy as np import pandas as pd cfg_t_total = 25000 cfg_t_step = 20 cfg_batch_size = 100 np.random.seed(12345) arparams = np.array([.75, -.25]) maparams = np.array([.65, .35]) ar = np.r_[1, -arparams] # add zero-lag and negate ma = np.r_[1, maparams] # add zero-lag y0 = sm.tsa.arma_generate_sample(ar, ma, cfg_t_total) y1 = sm.tsa.arma_generate_sample(ar, ma, cfg_t_total) y2 = sm.tsa.arma_generate_sample(ar, ma, cfg_t_total) df=pd.DataFrame({'a':y0,'b':y1,'c':y2}) df.head(100).plot() df.head(5) # create training data format X = df.unstack() y = X.groupby(level=0).shift(-cfg_t_step) idx_keep = ~(y.isnull()) X = X.ix[idx_keep] y = y.ix[idx_keep] from keras.models import Sequential from keras.layers import Dense, LSTM # LSTM taken from github/fchollet/keras/blob/master/examples/stateful_lstm.py # how to do this...?! print('Creating Model') model = Sequential() model.add(LSTM(50, batch_input_shape=(cfg_batch_size, cfg_t_step, 1), return_sequences=True, stateful=True)) model.add(LSTM(50, batch_input_shape=(cfg_batch_size, cfg_t_step, 1), return_sequences=False, stateful=True)) model.add(Dense(1)) modelpile(loss='mse', optimizer='rmsprop') model.fit(X, y, batch_size=cfg_batch_size, verbose=2, validation_split=0.25, nb_epoch=1, shuffle=False)

推荐答案

查看此博客Philippe Remy的帖子.它说明了如何在keras中使用有状态LSTM.

Check out this blog post by Philippe Remy. It explains how to use stateful LSTMs in keras.

更多推荐

具有keras和多个序列的时间序列预测

本文发布于:2023-07-18 04:47:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141156.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列   多个   时间   keras

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!