-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeras_first_network.py
42 lines (32 loc) · 971 Bytes
/
keras_first_network.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
#
from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
# load pima indians dataset
dataset = numpy.loadtxt('pima-indians-diabetes-data.csv', delimiter=',')
# split into input (X) and output (Y) variables
X = dataset[:, 0:8]
Y = dataset[:, 8]
print(X.shape)
print(Y.shape)
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# compile the model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit the model
model.fit(X, Y, epochs=150, batch_size=10)
# evluate the model
scores = model.evaluate(X, Y)
print("{}: {}".format(model.metrics_names[1], scores[1]*100))
print(X[-1])
# calculate predictions
predictions = model.predict(X)
# round predictions
rounded = [round(x[0]) for x in predictions]
print(rounded)