# Your First Deep Learning Project in Python with Keras Step-by-Step
# https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/

# In this tutorial, you will discover how to create your first deep learning neural network model in Python using Keras.
# The steps you will learn in this tutorial are as follows:
#     Load Data
#     Define Keras Model
#     Compile Keras Model
#     Fit Keras Model
#     Evaluate Keras Model
#     Tie It All Together
#     Make Predictions

# first neural network with keras tutorial
from numpy import loadtxt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense


# load the dataset
dataset = loadtxt('pima-indians-diabetes.csv', delimiter=',')
# shape
print(dataset.shape)
# print a few
print("First 5 rows:\n", dataset[:5])


# split into input (X) and output (y) variables
X = dataset[:,0:8]
y = dataset[:,8]


# define the keras model
model = Sequential()
model.add(Dense(16, input_shape=(8,), activation='relu'))
model.add(Dense(16, activation='relu'))
model.add(Dense(16, activation='relu'))
model.add(Dense(1, activation='sigmoid'))


# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])


# fit the keras model on the dataset
model.fit(X, y, epochs=150, batch_size=10, verbose=1)


# evaluate the keras model; evaluate returns two values: loss & accuracy;
loss, accuracy = model.evaluate(X, y)
print('Accuracy: %.2f' % (accuracy*100))


# make class predictions with the model
predictions = (model.predict(X) > 0.5).astype(int)
# summarize the first 5 cases
for i in range(20):
	print('%s => %d (expected %d)' % (X[i].tolist(), predictions[i], y[i]))
    








