First Neural Network with Keras

January 2, 2017

Keras is a powerful easy-to-use Python library for developing and evaluating deep learningmodels.

It wraps the efficient numerical computation libraries Theano and TensorFlow and allows you to define and train neural network models in a few short lines of code.


System Requirements :

  1. Python 3 .6

  2. TensofFlow

  3. Keras

Dataset :

Pima Indians onset of diabetes dataset from UCI datasets respository


Code :


#1. Import Libraries
from keras.models import Sequential
from keras.layers import Dense
import numpy
import os

# fix random seed for reproducibility


#2. load pima indians dataset
dataset = numpy.loadtxt("", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]


#3. 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'))


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


#5. Fit the model, Y, epochs=150, batch_size=10)


#6. evaluate the model
scores = model.evaluate(X, Y)
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))


Explaination :

The code is divided into following steps -

1. Load Data.

2. Define Model.

3. Compile Model.

4. Fit Model.

5. Evaluate Model.


Reference :

Share on Facebook
Share on Twitter
Please reload

About Author

Dattatray Shinde have over 6+ years of experience in Software Design, Development & Maintenance of Web Based Applications; worked on Healthcare, Insurance, E-commerce and Learning Management System domains. Over 2.5 + years as Data Scientist worked mainly in predictive analytics, survey analytics, risk analytics platforms.

Featured Posts

SAS - 1. Starting with SAS ... How to Install University edition?

March 20, 2017

Please reload

Recent Posts

June 21, 2017

January 19, 2014

Please reload

Search By Tags
Please reload


Contact Me

Mobile: +91 - 956 130 9595

  • Google+ Social Icon
  • Facebook Social Icon
  • LinkedIn Social Icon
  • Twitter Social Icon

© 2023 by Dattatray Shinde