Building the LSTM model
The data is now in a format compatible with model development in Keras for LSTM modeling. Therefore, we will spend this section setting up and configuring the deep learning model for predicting stock quotes for Apple in 2017 and 2018.
Getting ready
We will perform model management and hyperparameter tuning of our model in this section. This will require importing the following libraries in Python:
from keras import models from keras import layers
How to do it...
This section walks through the steps to setting up and tuning the LSTM model.
- Import the following libraries from
keras
using the following script:
from keras import models, layers
- Build a
Sequential
model using the following script:
model = models.Sequential() model.add(layers.LSTM(1, input_shape=(1,5))) model.add(layers.Dense(1)) model.compile(loss='mean_squared_error', optimizer='adam')
- Transform the testing and training data sets into three-dimensional arrays using the following script:
xtrain = xtrain.reshape((xtrain...