0
$\begingroup$

So I'm learning RNN, and tried to do a prediction LSTM, but I do not understand how the output works. I have this LSTM RNN:

lstm_model = Sequential()
lstm_model.add(LSTM(100, batch_input_shape=(BATCH_SIZE, TIME_STEPS, x_t.shape[2]), dropout=0.0, recurrent_dropout=0.0, stateful=False,   kernel_initializer='random_uniform'))
lstm_model.add(Dropout(0.5))
lstm_model.add(Dense(25,activation='relu'))
lstm_model.add(Dense(1,activation='sigmoid'))
optimizer = optimizers.RMSprop(lr=0.003)
lstm_model.compile(loss='mean_squared_error', optimizer=optimizer)

and fit with:

history = lstm_model.fit(x_t, y_t, epochs=300, verbose=2, batch_size=BATCH_SIZE,
                    shuffle=False, validation_data=(trim_dataset(x_val, BATCH_SIZE),
                    trim_dataset(y_val, BATCH_SIZE)), callbacks=[csv_logger])

When I then try to predict using

gotten = lstm_model.predict(x_test_t[-500:],batch_size=BATCH_SIZE)

Will I get only one new output? I'm very confused with the way you run and get predictions

Thanks for the help

$\endgroup$
0
$\begingroup$

With your current model, you will indeed get a single scalar output. This is because the last layer is Dense with just 1 unit.

In other words, with this model you can map a sequence to a single value that may represent, e.g., the label of the series or its next value depending on what target you train the network on.

$\endgroup$
  • 1
    $\begingroup$ Thank you, I think I now understand better So if I wanted a n-dimensional array has result I would have to change the net to have a layer with n units and create the appropriate expected result, and that would give me the result for the following n days? $\endgroup$ – Joao Ferreira Jul 2 at 23:15
  • $\begingroup$ That's the simplest way to do it, so in short yes. $\endgroup$ – pcko1 Jul 3 at 7:44
  • 1
    $\begingroup$ Thank you for your help :) $\endgroup$ – Joao Ferreira Jul 3 at 8:14

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.