# Predicting time series with NNs: should the data set be shuffled?

Suppose I'm trying to predict time series with a neural network. The data set is created from a single column of temporal data, where the inputs of each pattern are [t-n, t-n+1, ... , t], t being the time step and n the embedding size, and [t+1] being the target (predicting the "next step" of the series). Here is the question: if I use such a data set for NN training, should I shuffle it? Shuffling is usually done to avoid overfitting by preventing the NN from memorizing the pattern order. However, in case of time series, could pattern order be a form of information that I shouldn't deprive the NN of? The issue becomes even more severe if recurrent NNs are concerned, where every pattern recurrently receives information about the previous pattern: would a RNN benefit if patterns were in order?

-

Say you have a single time series you want to learn on. Then you can use the first half for the development of your model and the second half for testing.

You now cut your two halfs into windows individually and can shuffle those of the training set.

From what I know, the shuffling is actually not because of generalization, but because of optimization. It is sometimes more efficient to optimize a sum of functions (in this case, one loss function per time window) if you do not look at their sum, but estimate the gradient by looking at the gradients of a subset of the sum. Look at recent publications by Nicolas Le Roux and Marc Schmidt for this topic.

-
Thanks, I'll check it out. Maybe I just had a wrong idea stuck in my head all along the road :) –  anna-earwen Oct 25 '12 at 11:03
Hmm... Now, that only applies to gradient-based learning algorithms. I.e., if I use a population-based approach such as PSO or GA, shuffling may be completely irrelevant. –  anna-earwen Oct 25 '12 at 11:05
It relates whether you are doing online learning, e.g. you estimate your loss or its gradient by only looking at a fraction. Nothing stops you from doing that with population based algorithms as well. However, you are right, this is mostly done for gradient based optimization only. –  bayerj Oct 28 '12 at 19:37
Even for on-line learning, if past patterns are revisited, they should probably be shuffled. I carried out some experiments a few days ago and saw what I expected to see: backpropagation performed worse without shuffling, and PSO wasn't really affected (although I have to say no statistical significance tests were carried out... yet). –  anna-earwen Oct 29 '12 at 20:22
That's what I'm saying, sorry. In the case of offline learning, where your loss is exact wrt training set, you don't have to shuffle. If you shuffle, you will get the same number. This is not the case for online algorithms, where you only look at a fraction of your training set and thus just an estimate of your training loss. –  bayerj Oct 30 '12 at 7:07