1
votes

I'm trying to fit a time series to an LSTM with Keras and I have some issues with the input shape.

In this article : https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/ , the autor choose the shape : (trainX.shape[0], 1, trainX.shape[1]) But the input of an LSTM should be : (samples, timesteps, features) So shouldn't he have chosen this shape : (1 , trainX.shape[0] , trainX.shape[1]) ? Since it's a single serie with multiple steps over time

I tried to do that with my own time series but it does not work, so what did I miss ? My situation is exactly the same than the article. It works when I reshape like the autor did but It does not work my way.

Thanks.

1

1 Answers

0
votes

The author is using stateful=True;

This means that every new input will be considered as "following steps" of the previous input until they manually call model.reset_states().

I'm not sure why they are using this, but some reasons are:

  • We want the output of one step to contruct the input of the next step
  • We have too long sequences that don't fit the memory