-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathL11 PID Save to JSON and H5.py
35 lines (28 loc) · 1.03 KB
/
L11 PID Save to JSON and H5.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
#import libraries
from keras.models import Sequential
from keras.layers import Dense
import numpy
import os
seed = 7
numpy.random.seed(seed)
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter = ",")
X = dataset[:,0:8]
Y = dataset[:,8]
def baseline_model():
model = Sequential()
model.add(Dense(12, input_dim = 8, init = 'uniform', activation = 'relu'))
model.add(Dense(8, init = 'uniform', activation = 'relu'))
model.add(Dense(1, init = 'uniform', activation = 'sigmoid'))
model.compile(loss = 'binary_crossentropy', optimizer='adam', metrics=['accuracy'])
return model
model = baseline_model()
model.fit(X, Y, nb_epoch = 100, batch_size= 10, verbose = 0)
scores = model.evaluate(X, Y, verbose = 0)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
#serialize model structure to JSON
model_json = model.to_json()
with open("model.json", "w") as json_file:
json_file.write(model_json)
#serialize model weights to HDF5
model.save_weights("model.h5")
print("Saved!")