-
Notifications
You must be signed in to change notification settings - Fork 4
/
lstm.py
44 lines (30 loc) · 937 Bytes
/
lstm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
LSTM RNN model
created by: Ban Luong
"""
from keras.models import Sequential
from keras.layers import LSTM, Dropout, Dense
from keras.optimizers import Adam
def build_model(LSTM_unit, dropout, lr, train):
model = Sequential()
model.add(LSTM(units=LSTM_unit, return_sequences=True, input_shape=(train.shape[-2:])))
model.add(Dropout(dropout))
model.add(LSTM(units=LSTM_unit, return_sequences=True))
model.add(Dropout(dropout))
model.add(LSTM(units=LSTM_unit, return_sequences=True))
model.add(Dropout(dropout))
model.add(LSTM(units=LSTM_unit))
model.add(Dropout(dropout))
model.add(Dense(units=1))
model.compile(optimizer=Adam(lr), loss='mean_squared_error')
return model
model = build_model(50, 0.2, 0.001, X_train)
model.summary()
history = model.fit(
X_train, y_train,
epochs=50,
batch_size=128,
validation_split=0.1,
verbose=1,
shuffle=False
)