Skip to content

Instantly share code, notes, and snippets.

@breadplop
Created November 4, 2018 07:37
Show Gist options
  • Save breadplop/c75e68c73eb3bd1ff09fe5a40e9e349f to your computer and use it in GitHub Desktop.
Save breadplop/c75e68c73eb3bd1ff09fe5a40e9e349f to your computer and use it in GitHub Desktop.
BT4221 Assignment 4 Question 1 - Pima Indians Dataset
#### Create first network with Keras
from keras.models import Model
from keras.layers import Input, Dense
from keras.callbacks import ModelCheckpoint, EarlyStopping
import numpy as np
batch_size = 10
epochs = 10
validation_split = 0.1
# Load Pima Indians Dataset
data = np.loadtxt("pima-indians-diabetes.csv", delimiter=',', skiprows=1)
#data = np.loadtxt("data.csv", delimiter=',', skiprows=1)
X = data[:,0:8]
Y = data[:,8]
# Create Model
input_layer = Input(shape=(8,)) #input layer
layer = Dense(10, activation='tanh')(input_layer) #hidden layer
output_layer = Dense(1, activation = 'sigmoid')(layer) #output layer
model = Model(inputs=input_layer, outputs= output_layer)
# Compile Model
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
# Fit the Model
model.fit(x=X, y=Y,
batch_size=batch_size,
epochs=epochs,
validation_split=0.33)
# Evaluate the model
scores = model.evaluate(X, Y)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
#for fun
from keras.utils import plot_model
plot_model(model, to_file='model.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment