Constructing the RNN model

Having preprocessed the dataset, let's use the test dataset to construct the RNN model. We can do that using the following snippet:

# Importing the Keras libraries and relevant packages
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM

# Initialise the RNN model
regressor = Sequential()

# Add the input layer and the LSTM layer
regressor.add(LSTM(units = 4, activation = 'sigmoid', input_shape = (None, 1)))

# Add the output layer
regressor.add(Dense(units = 1))

# Compile the RNN
regressor.compile(optimizer = 'adam', loss = 'mean_squared_error')

# Fit the RNN to the Training set
regressor.fit(X_train, y_train, batch_size = 5, epochs = 100)

Each of these statements does something specific and is commented out. Please go through each of them one by one so that you have a better understanding of what we are trying to do and why that step is required. Once you run this script, the RNN model will start to be constructed. The script should output the progress as it's built on. The first few entries are shown in Figure 12.9:

Figure 12.9: Output of the preceding snippet when constructing the RNN model
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset