forked from felipeam86/clue_hackathon_code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
78 lines (63 loc) · 2.04 KB
/
model.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
LSTM models used for predicting
"""
import os
from os.path import join as pj
from keras.layers import LSTM, Dense, Activation, Dropout
from keras.models import Sequential
base_dir = os.path.dirname(__file__)
weights_dir = pj(base_dir, 'weights')
def get_model(model=1, input_size=16, output_size=16, maxlen=90):
"""Creates as keras LSTM model
Parameters
----------
model: int
Number of layers of the model
input_size: int
Number of input symptoms to take into account
output_size: int
Number of outputs symptoms to predict
maxlen: int
Number of days in the past that are required to generate next day prediction
Returns
-------
model: keras.model
Model used for training and/or prediction
"""
assert model in [1, 2]
if model == 1:
model = Sequential()
model.add(LSTM(128, input_shape=(maxlen, input_size)))
model.add(Dropout(0.5))
model.add(Dense(output_size))
model.add(Activation('sigmoid'))
elif model == 2:
model = Sequential()
model.add(LSTM(256, input_shape=(maxlen, input_size), return_sequences=True))
model.add(Dropout(0.5))
model.add(LSTM(256))
model.add(Dropout(0.6))
model.add(Dense(output_size))
model.add(Activation('sigmoid'))
return model
def get_weight_path(model, input_size, output_size, maxlen):
"""Creates the model name based on the parameters
Parameters
----------
model: int
Number of layers of the model
input_size: int
Number of input symptoms to take into account
output_size: int
Number of outputs symptoms to predict
maxlen: int
Number of days in the past that are required to generate next day prediction
Returns
-------
:string
Name of the model
"""
template = "lstm_{}_layers_{}_input_size_{}_output_size_{}_maxlen.hdf5"
return pj(weights_dir, template.format(model, input_size, output_size, maxlen))