简体   繁体   English

使用具有Keras的LSTM进行时间序列预测的不同大小的预测因子

[英]Predictors of different size for time series prediction using LSTM with Keras

I would like to predict time series values X using another time series Y and the past value of X .In detail, I would like to predict X at time t ( Xt ) using ( Xt-p ,..., Xt-1 ) and ( Yt-p ,..., Yt-1 , Yt ) with p the dimension of the "look back". 我想用另一个时间序列YX的过去值来预测时间序列值X详细地说,我想在时间t( Xt )使用( Xt-p ,..., Xt-1 )预测X.和( Yt-p ,..., Yt-1Yt ),其中p为“回顾”的维度。 So, my problem is that I do not have the same length for my 2 predictors. 所以,我的问题是我的2个预测变量的长度不一样。 Let's use a exemple to be clearer. 让我们用一个例子来说明一点。

If I use a timestep of 2, I would have for one observation : [(Xt-p,Yt-p),...,(Xt-1,Yt-1),(??,Yt)] as input and Xt as output. 如果我使用2的时间步长,我将进行一次观察: [(Xt-p,Yt-p),...,(Xt-1,Yt-1),(??,Yt)]作为输入和Xt作为输出。 I do not know what to use instead of the ?? 我不知道该用什么代替??

I understand that mathematically speaking I need to have the same length for my predictors, so I am looking for a value to replace the missing value. 我理解,从数学上讲,我需要为预测变量设置相同的长度,所以我正在寻找一个值来替换缺失的值。

I really do not know if there is a good solution here and if I could to something so any help would be greatly appreciated. 我真的不知道这里是否有一个很好的解决方案,如果我能做到这一点,那么任何帮助将不胜感激。

Cheers ! 干杯!

PS : you could see my problem as if I wanted to predict the number of ice cream sell one day in advance in a city using the forcast of weather for the next day. PS:你可以看到我的问题,好像我想用第二天的天气预测在一个城市提前一天预测出售的冰淇淋数量。 X would be the number of ice cream and Y could be the temperature. X是冰淇淋的数量, Y可能是温度。

You could eg do the following: 您可以执行以下操作:

input_x = Input(shape=input_shape_x)
input_y = Input(shape=input_shape_y)
lstm_for_x = LSTM(50, return_sequences=False)(input_x)
lstm_for_y = LSTM(50, return_sequences=False)(input_y)
merged = merge([lstm_for_x, lstm_for_y], mode="concat") # for keras < 2.0
merged = Concatenate([lstm_for_x, lstm_for_y])
output = Dense(1)(merged)

model = Model([x_input, y_input], output)
model.compile(..)
model.fit([X, Y], X_next)

Where X is an array of sequences, X_forward is X p -steps ahead and Y is an array of sequences of Ys . 其中X是序列的阵列, X_forwardX p -steps前进, Y是序列的阵列Ys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM