-
Notifications
You must be signed in to change notification settings - Fork 15
/
example.py
32 lines (24 loc) · 997 Bytes
/
example.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
from keras.models import Sequential
from keras.layers import Dense
import numpy
from visual_callbacks import AccLossPlotter
numpy.random.seed(7)
# load pima indians dataset
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]
# create 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'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Instantiate AccLossPlotter to visualise training
plotter = AccLossPlotter(graphs=['acc', 'loss'], save_graph=True)
# Add your plotter to the fit function's callbacks list
model.fit(X, Y, validation_split=0.2, nb_epoch=100, batch_size=28, callbacks=[plotter])
# evaluate the model
scores = model.evaluate(X, Y)
input('Press ENTER to continue...')