Skip to content

Instantly share code, notes, and snippets.

@vihar
Created February 10, 2018 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vihar/682dccbe9f92b68f882b42c754df07f3 to your computer and use it in GitHub Desktop.
Save vihar/682dccbe9f92b68f882b42c754df07f3 to your computer and use it in GitHub Desktop.
# Importing Keras Sequential Model
from keras.models import Sequential
from keras.layers import Dense
import numpy
# Initializing the seed value to a integer.
seed = 7
numpy.random.seed(seed)
# Loading the data set (PIMA Diabetes Dataset)
dataset = numpy.loadtxt('datasets/pima-indians-diabetes.csv', delimiter=",")
# Loading the input values to X and Label values Y using slicing.
X = dataset[:, 0:8]
Y = dataset[:, 8]
# Initializing the Sequential model from KERAS.
model = Sequential()
# Creating a 16 neuron hidden layer with Linear Rectified activation function.
model.add(Dense(16, input_dim=8, init='uniform', activation='relu'))
# Creating a 8 neuron hidden layer.
model.add(Dense(8, init='uniform', activation='relu'))
# Adding a output layer.
model.add(Dense(1, init='uniform', activation='sigmoid'))
# Compiling the model
model.compile(loss='binary_crossentropy',
optimizer='adam', metrics=['accuracy'])
# Fitting the model
model.fit(X, Y, nb_epoch=150, batch_size=10)
scores = model.evaluate(X, Y)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1] * 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment