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 :
Python 3 .6
TensofFlow
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("pima-indians-diabetes.data.txt", 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 model.fit(X, 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 :
https://machinelearningmastery.com/tutorial-first-neural-network-python-keras/