-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy pathann.py
More file actions
42 lines (33 loc) · 1.18 KB
/
Copy pathann.py
File metadata and controls
42 lines (33 loc) · 1.18 KB
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
from __future__ import absolute_import
from six import with_metaclass
from keras.models import Sequential
from keras.layers import recurrent
from keras.layers import core
from bulbea.learn.models import Supervised
class ANN(Supervised):
pass
class RNNCell(object):
RNN = recurrent.SimpleRNN
GRU = recurrent.GRU
LSTM = recurrent.LSTM
class RNN(ANN):
def __init__(self, sizes,
cell = RNNCell.LSTM,
dropout = 0.2,
activation = 'linear',
loss = 'mse',
optimizer = 'rmsprop'):
self.model = Sequential()
self.model.add(cell(
units=sizes[1],return_sequences=True
))
for i in range(2, len(sizes) - 1):
self.model.add(cell(sizes[i], return_sequences = False))
self.model.add(core.Dropout(dropout))
self.model.add(core.Dense(sizes[-1]))
self.model.add(core.Activation(activation))
self.model.compile(loss = loss, optimizer = optimizer)
def fit(self, X, y, *args, **kwargs):
return self.model.fit(X, y, *args, **kwargs)
def predict(self, X):
return self.model.predict(X)