An RNN model can be easily built in Keras by adding the SimpleRNN layer with the number of internal neurons and the shape of input tensor, excluding the number of samples dimension. The following code creates, compiles, and fits the SimpleRNN:
# create and fit the SimpleRNN model
model = Sequential()
model.add(SimpleRNN(units=4, input_shape=(X_train.shape[1],
X_train.shape[2])))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(X_train, Y_train, epochs=20, batch_size=1)
As our dataset is small, we use a batch_size of 1 and train for 20 iterations, but for larger datasets, you would need to tune the value of these and other hyper-parameters.
The model is structured as follows:
_________________________________________________________________ Layer (type) Output Shape Param...