How to add LSTM layers to keras model?
LSTM stands for Long Short Term Memory comes under RNN. LSTM has mostly used the time or sequence-dependent behavior example texts, stock prices, electricity.
The LSTM model contains one or many hidden layers.
It is followed by a standard output layer.
import keras
from keras.models import Sequential
from keras.layers import LSTM
import numpy as np
We will define the model and Add a LSTM layer to it.
# define model where LSTM is also output layer
model = Sequential()
model.add(LSTM(1, input_shape=(10,1)))
model.compile(optimizer='adam', loss='mse')
We will define a sample array to run in the model.
y = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).reshape((1,10,1))
print(model.predict(y))
[[0.01069558]]