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

✔ 13+ years of experience in the Software Industry; Over 6.5+ years of experience in machine learning and deep learning projects.

✔ Hands-on Data Science practitioner; a Leading team of data scientists, Python developers, UI developers, and business analysts for multi-million dollar projects

✔ Designed and developed DevOps enabled MLOPs strategy and components from scratch which had saved 80% data annotation and 40% development time for clients.

Featured Posts
Search By Tags
No tags yet.