0

I am creating a LSTM model in Keras with Python and I have the next context:

I have a regression problem, and I want a LSTM model of X different layers that inputs a sequence of 40 elements and outputs the next Y values. Those Y values should be dynamic. This is: maybe I want to predict the next 10 elements for a sequence of 40 elements in one case, but in other case I want to predict the next 100 values.

My question is: is it possible?

I have the next code:

model = Sequential()
model.add(LSTM(200, activation='relu', input_shape=(trainx.shape[1], trainx.shape[2])))
model.add(RepeatVector(outputs))
model.add(LSTM(200, activation='relu', return_sequences=True))
model.add(TimeDistributed(Dense(100, activation='relu')))
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mse', optimizer='adam')
# fit network
history = model.fit(trainx, trainy, epochs=100, batch_size=300, verbose=1)


# make predictions
trainPredict = model.predict(trainx)
jartymcfly
  • 1,945
  • 9
  • 30
  • 51
  • It is using the `stateful=True` approach described [here](https://stackoverflow.com/questions/38714959/understanding-keras-lstms/50235563#50235563) and [here](https://stackoverflow.com/questions/46901371/how-to-deal-with-multi-step-time-series-forecasting-in-multivariate-lstm-in-kera) – Daniel Möller Feb 04 '19 at 13:59
  • I edited my question with some code. Can you reedit the code with the stateful=True in order to have, for example, 40 element prediction? – jartymcfly Feb 05 '19 at 07:47

0 Answers0