Home > front end >  How to get result for each timesteps in LSTM Model Keras
How to get result for each timesteps in LSTM Model Keras

Time:08-27

I have a limited dataset with four timesteps, and each timestep has 17 variables to predict. So the input shape is input_shape=(4, 17). For example for a person with ID 1, the would be like this:

time 1 = x1,x2,x3,x4..., x16, x17

time 2 = x1,x2,x3,x4..., x16, x17

time 3 = x1,x2,x3,x4..., x16, x17

time 4 = x1,x2,x3,x4..., x16, x17

There is 1 Y for each timestep. I need to have the output for each timestep. Here is my code:

model = Sequential()
model.add(Masking(mask_value=-2., input_shape=(4, 17)))
model.add(LSTM(150, activation='tanh', return_sequences=True)) 
model.add(LSTM(150, activation='tanh', return_sequences=True))
model.add(Dropout(0.2))
model.add(Dense(1, activation='relu')) 
model.compile(optimizer='adam', loss='mean_absolute_error')
model.summary()

I have add return_sequence = True for each LSTM layer. But I'm not sure if this is the right code or not.

CodePudding user response:

getting prediction for each timestep in your LSTM has more to do with pre-processing the data than it does the actual design of the LSTM. This video may be able to provide you with some helpful information, and provides a link to the code used to design the LSTM:

https://www.youtube.com/watch?v=tepxdcepTbY

  • Related