First Neural Network with Keras

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 numpy.random.seed(7)

os.chdir("D://DeepLearning//FirstExampleWithKeras//") print(os.getcwd())

#2. load pima indians dataset dataset = numpy.loadtxt("", delimiter=",") print(type(dataset)) # 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 :

About Author

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

Featured Posts
Recent Posts