1
$\begingroup$

So I am trying time series forecasting using LSTM's. The aim is to predict $Y$ given $X$ using regression.

I had already converted the input data into a sliding window format such that if my input data was of the form:

X = [x0, x1, x2,.....]
Y = [y0, y1, y2,.....]

Then I converted it into:

Xnew = [(x0, x1, x2), (x1, x2, x3), (x2, x3, x4),...]
Y    = [         y2,           y3,           y4,...]

Still, upon training my data I find a very high validation_loss.

Since validation_split takes only the fraction of the data from the end, I thought maybe I should try and randomize the data before training it. However, in that way, will time series have any meaning?

I found a similar question, but I had apparently already tried what was suggested: Is it valid to shuffle time-series data for a prediction task?

$\endgroup$
2
  • $\begingroup$ Is your model linear regression or an LSTM? You mention both in the first paragraph. $\endgroup$
    – zachdj
    Commented May 19, 2020 at 13:15
  • 1
    $\begingroup$ It's an LSTM. Sorry I made a mistake. I edited it $\endgroup$
    – Zoro101
    Commented May 19, 2020 at 13:17

3 Answers 3

1
$\begingroup$

Shuffling data would not seem to make sense here, since your model has "memory". You're not predicting $y_i$ from only $x_i$, but also $x_{i-1}$ and $x_{i-2}$. If you shuffle the data and perform prediction, you are implying that $x_1, x_2, x_3$ should give the same value as $x_2, x_1, x_3$ or $x_9, x_5, x_3$, or any series of values that merely ends in $x_3$ (since the target value is always $y_3$, regardless of the other $x$). If your target value actually does depend on preceding variables, shuffling the data breaks that relationship. If it does not depend on preceding values, it's arguably not a time-series model, since the ordering of observations is irrelevant.

$\endgroup$
1
  • $\begingroup$ Yeah, that seems to make sense. So what do you suggest could be done to reduce the validation loss? $\endgroup$
    – Zoro101
    Commented May 19, 2020 at 13:31
1
$\begingroup$

In RNN sequence is utmost important. So strict no for shuffling as it will break the sequence.

Though I think, it will be good if we can shuffle different batch series, such that if a particular series used in batch i, next time that series can be the part of some different batch say j.

If you try, please share your results.

$\endgroup$
0
$\begingroup$

LSTMs have memory, so it matters in what order the model sees your samples. From the answer you linked:

The model's internal parameters are changing and persisting with each new example it sees. The current prediction depends on the last prediction. Recurrent neural networks have memory, so order matters.

If you're worried that your estimate of loss is inaccurate, you can obtain a more stable estimate of validation_loss by using time-series cross-validation.

If you are instead worried that the performance of your model is insufficient, keep in mind that hyperparameter tuning will likely be important for this problem. No need to fix the size of the historical window at 3; perhaps a larger window size is better? Other hyperparameters such as the size of the hidden state and the number of recurrent layers can also have a big impact on performance.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.