/
ANN
58 lines (42 loc) · 1.3 KB
/
ANN
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from keras.models import Sequential
from keras.layers import Dense
import numpy
import pandas as pd
#fix random seed for reproducibility
numpy.random.seed(7)
#load dataset
dataset=pd.read_csv("pima-indians-diabetes.data.csv")
#print(dataset.index.tolist())
#
#set a columns name
dataset.columns=[0,1,2,3,4,5,6,7,8]
#print(dataset.columns.values.tolist())
#Split the dataset input-train (X) and Output-test (Y)
X=dataset.iloc[:,0:8]
Y=dataset.iloc[:,8]
from tensorflow import keras
#Create a 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, verbose=2)
# Evaluate the model
#score=model.evaluate(X,Y)
#print("\n %s: %.2f%%" % (model.metrics_names[1], score[1]*100))
# Calculate predictions
prediction=model.predict(X)
#print(prediction)
rounded=[round(x[0]) for x in prediction ]
print(rounded[0:10])
#split into input (X) and output (Y) variables
#X=dataset
#Y=dataset[:,8]
# 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'))