I have multiple separate time series and would like to train the same LSTM network on them. How to do in this situation? I can't just concatenate timeseries (along time), because I am afraid network will be confused by jumps at the points of concatenation.

How to overcome?

  • 2
    $\begingroup$ Can you clarify a little bit more? Do these time series have the same length? what do you want the RNN to do eventually etc. $\endgroup$ – Amani May 30 '18 at 10:23
  • $\begingroup$ All time series are of different lengths (coincidences are not excluded of course). The goal is to predict next one or more samples on the basis of previous ones. $\endgroup$ – Dims May 30 '18 at 11:20
  • $\begingroup$ Is there a reason for the length variation?, can't resample them to make them have the same number of samples? $\endgroup$ – Amani May 30 '18 at 11:55
  • $\begingroup$ @Amani they represent different periods of observations of some process; if I resample them, I will damage significant data $\endgroup$ – Dims May 30 '18 at 12:16
  • 1
    $\begingroup$ LSTM is invariant to 'speed'. Meaning, its strength is detecting patterns whether or not they have the same length. I thing it's worth trying at least. $\endgroup$ – Amani May 30 '18 at 14:02

just re-use


on the fresh datasets using the already trained model, simple as that :) !

(given that you do it in Keras)

  • $\begingroup$ What will it do at the beginning? Make previous sample zero? $\endgroup$ – Dims May 30 '18 at 12:17
  • 1
    $\begingroup$ if it's part of the same code, the weights and the state will have the updated values, utilizing the learnt information from the previous training session. $\endgroup$ – pcko1 May 30 '18 at 12:22
  • $\begingroup$ But won't it have the same effect as if I concatenated series? $\endgroup$ – Dims May 30 '18 at 12:58
  • 3
    $\begingroup$ good idea, I guess it will have the similar "jump". Therefore consider model.reset_states() before feeding the new dataset and calling model.fit() :) $\endgroup$ – pcko1 May 30 '18 at 13:13

If I understand your question correctly, the reason you think cannot concatenate your time series into a one dataset is because of their different length. Depending on your problem, you can handle this issue in multiple manners in preprocessing. But the more common way is to use sequence padding. Preprocessing methods are natively implemented in keras: https://keras.io/preprocessing/sequence/.

Hope that answers your question.


The answer of @pcko1 anwser would work but'll force you into using a batch size of 1, which might give you a much higher convergence time.

  • 1
    $\begingroup$ No, length is irrelevant, since I would concatenate series "horizontally", along time. $\endgroup$ – Dims May 30 '18 at 12:15
  • $\begingroup$ Could you reformulate your question to make sure that If I understand correctly, the different periodicities of your time series is your problem ? What I mean is that you have several time series data referring to the same problem but sampled differently ? Am I right ? $\endgroup$ – Alexis May 30 '18 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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