-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathL17 Ionos Learning Rate Schedule.py
More file actions
36 lines (29 loc) · 1.01 KB
/
L17 Ionos Learning Rate Schedule.py
File metadata and controls
36 lines (29 loc) · 1.01 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
#time-based learning rate schedule
#learning rate decay over epochs
import pandas
import numpy
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
from sklearn.preprocessing import LabelEncoder
seed = 7
numpy.random.seed(seed)
dataframe = pandas.read_csv("ionosphere.csv", header = 0)
dataset = dataframe.values
X = dataset[:, 0:34].astype(float)
Y = dataset[:,34]
#one hot encoding
encoder = LabelEncoder()
encoder.fit(Y)
Y = encoder.transform(Y)
#create model
model = Sequential()
model.add(Dense(34, input_dim=34, init = 'normal', activation = 'relu'))
model.add(Dense(1, init = 'normal', activation = 'sigmoid'))
epochs = 50
learning_rate = 0.1
decay_rate = learning_rate/epochs
momentum = 0.8
sgd = SGD(lr = learning_rate, momentum= momentum, decay = decay_rate, nesterov = False)
model.compile(loss = 'binary_crossentropy', optimizer = sgd, metrics = ['accuracy'])
model.fit(X, Y, validation_split=0.33, nb_epoch= epochs, batch_size = 28)