Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predicting a multiple forward time step of a time series using LSTM

Tags:

People also ask

What is multi step LSTM?

The Long Short-Term Memory network or LSTM is a recurrent neural network that can learn and forecast long sequences. A benefit of LSTMs in addition to learning long sequences is that they can learn to make a one-shot multi-step forecast which may be useful for time series forecasting.

Can LSTM be used for multivariate forecasting?

I was trying to forecast the future values of a variable where it not only depends on the previous values of itself but it also depends on the previous/current values of the other variables.

Can LSTM be used for time series forecasting?

One of the most advanced models out there to forecast time series is the Long Short-Term Memory (LSTM) Neural Network. According to Korstanje in his book, Advanced Forecasting with Python: “The LSTM cell adds long-term memory in an even more performant way because it allows even more parameters to be learned.

How many time steps can LSTM remember?

It is a standard LSTM and has two LSTM layers, each layer has 19 time steps, and each LSTM cell contains 100 neutrons and uses the last time step value of the sequence as a training label and uses the previous time steps values as the training data.


I want to predict certain values that are weekly predictable (low SNR). I need to predict the whole time series of a year formed by the weeks of the year (52 values - Figure 1)

Figure 1: Year time series by week

My first idea was to develop a many-to-many LSTM model (Figure 2) using Keras over TensorFlow. I'm training the model with a 52 input layer (the given time series of previous year) and 52 predicted output layer (the time series of next year). The shape of train_X is (X_examples, 52, 1), in other words, X_examples to train, 52 timesteps of 1 feature each. I understand that Keras will consider the 52 inputs as a time series of the same domain. The shape of the train_Y are the same (y_examples, 52, 1). I added a TimeDistributed layer. My thought was that the algorithm will predict the values as a time series instead of isolated values (am I correct?)

The model's code in Keras is:

y = y.reshape(y.shape[0], 52, 1) X = X.reshape(X.shape[0], 52, 1) # design network model = Sequential() model.add(LSTM(n_neurons, input_shape=(X.shape[1], X.shape[2]), return_sequences=True)) model.add(TimeDistributed(Dense(1))) model.compile(loss='mean_squared_error', optimizer='adam') # fit network model.fit(X, y, epochs=n_epochs, batch_size=n_batch, verbose=2) 

Figure 2: Many-to-many LSTM architecture

The problem is that the algorithm is not learning the example. It is predicting values very similar to the attributes' values. Am I modeling the problem correctly?

Second question: Another idea is to train the algorithm with 1 input and 1 output, but then during the test how will I predict the whole 2015 time series without looking to the '1 input'? The test data will have a different shape than the training data.