Instantiate a sequential model

Next, we instantiate a sequential model and add the following layers:

  • A simple RNN
  • A dense layer with one output

Following are the steps of a simple RNN:

  1. The next code listing shows model creation and compilation:
model = Sequential() model.add(SimpleRNN(n_neurons, batch_input_shape=(n_batch, X.shape[1], X.shape[2]), stateful=True)) model.add(Dense(1))
  1. Then, we compile the model using model. compile(..) with loss and optimizers, shown as follows:
model.compile(loss='mean_squared_error', optimizer='adam')

We are using mean squared error (MSE) as the loss function and Adam as an optimizer. MSE is a loss function that uses a sum of squared difference between the predicted value and actual value divided b ...

Get Keras Deep Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.