Different sized predictors for time series forecasting using LSTM with Keras
I would like to predict time series values X
using a different time series Y
and past value X
. In detail, I would like to predict the X at time t ( Xt
), by using ( Xt-p
, ..., Xt-1
) and ( Yt-p
, ... Yt-1
, Yt
) with p dimension "look". So my problem is that I don't have the same length for my 2 predictors. Let's use an example to be clearer.
If I use timestep of 2, I would do for one observation
[(Xt-p,Yt-p),...,(Xt-1,Yt-1),(??,Yt)]
, as input and Xt
as output. I don't know what to use instead??
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 don't know if there is a good solution here and if I could do something, so any help would be greatly appreciated.
Greetings!
PS: you could see my problem as if I wanted to predict how much ice cream is sold in one day in the city using the weather forecast for the next day. X
will be the amount of ice cream and Y
may be the temperature.
source to share
You can, for example, 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
- X
p
is in front, and Y
is an array of sequences Ys
.
source to share