Eren
Eren

Reputation: 169

Is this the right way to predict a time series with the stateful LSTM neural network?

I am using LSTM neural networks (stateful) for time series prediction.

I'm hoping that the stateful LSTM can capture the hidden patterns and make a satisfactory prediction (the physical law that cause the variation of the time series is not clear).

I have a time series X with a length of 1500 (actual observational data), and my purpose is to predict the future 100.

I suppose predict the next 10 will be more promising than predict the next 100 (is that right?).

So, I prepare the training data like this (always using 100 values to predict the next 10; x_n denotes the n-th element in X):

shape of trainX: [140, 100, 1]
shape of trainY: [140, 10, 1]
---
0: [x_0,  x_1, ...,  x_99]  -> [x_100, x_101, ..., x_109]
1: [x_10, x_11, ..., x_109] -> [x_110, x_111, ..., x_119]
2: [x_20, x_21, ..., x_119] -> [x_120, x_121, ..., x_129]
                     ...
139: [x_1390, x_1391, ..., x_1489] -> [x_1490, x_1491, ..., x_1499]
---

After the training, I want to use the model to predict the next 10 values [x_1500 - x_1509] with [x_1400 - x_1499], and then predict the next 10 values [x_1510 - x_1519] with [x_1410 - x_1509].

Is this the right way?

After a lot of reading of documents and examples, I can train a model and make the prediction, but the result seems not satisfactory.

To validate the method, I assume that the last 100 (x_1400 - x_1499) values are unknown, and remove them from trainX and trainY, then try to train a model and predict them. Lastly, compare the predicted values with the observed values.

Any suggestions or comments will be appreciated.

The time series looks like this: enter image description here

Upvotes: 2

Views: 1209

Answers (1)

Marcin Możejko
Marcin Możejko

Reputation: 40506

Your question is really complexed. Before I will try to answer it - I'll share my doubts with you about is it sensible to use LSTM for your task. You want to use a really advanced model (LSTM are capable to learn really complexed patterns) to a time series which seems to be relatively easy. Moreover - you have a really small amout of data. To be honest - I would try to train simpler and easier methods first (like ARMA or ARIMA).

To answer your question - if your approach is good - it seems to be reasonable. Other reasonable methods are predicting all 100 steps or e.g. 50 steps twice. With 10 steps you might come across error cumulation - but still it might be a good method.

As I mentioned earlier - I would rather try easier ML method for this task but if you really want to use LSTM you may tackle this problem in a following way:

  1. Define metaparameters like number of steps ahead you want to predict, the size of input fed to network.
  2. Try to use e.g. grid search in order to find the best value of this metaparameters. Evaluate each setup using k-fold crossvalidation.
  3. Retrain final model using the best metaparameter setup.

You have relatively small amount of data so you may easily find the best values of hyperparameters. This will also show you if your approach is good or not - simply check the results provided by the best solution.

Upvotes: 4

Related Questions