Let's now see what it takes to build and train an LSTM model for stock price prediction in Keras. First, some imports and constant settings:
import kerasfrom keras import backend as Kfrom keras.layers.core import Dense, Activation, Dropoutfrom keras.layers.recurrent import LSTMfrom keras.layers import Bidirectionalfrom keras.models import Sequentialimport matplotlib.pyplot as pltimport tensorflow as tfimport numpy as npsymbol = 'amzn'epochs = 10num_neurons = 100seq_len = 20pred_len = 1shift_pred = False
shift_pred is used to indicate whether we want to predict an output sequence of prices versus just a single output price. If it's True, we'll predict X2, X3, ..., Xn+1 from the X1, X2, X3, ..., Xn input, as we ...