Classify Handwritten Digits using Deep learning with Tensorflow by@itsvinayak

# Classify Handwritten Digits using Deep learning with Tensorflow

Deep learning is a subpart of machine learning and artificial intelligence which is also known as deep neural network this networks are capable of learning unsupervised from provided data which is unorganized or unlabeled. today, we will implement a neural network in 6 easy steps using TensorFlow to classify handwritten digits. We will use NumPy, Matplotlib, NumPy and Tensorflow to build a deep learning neural network. We'll use these modules to train our neural network and make a prediction.

### @itsvinayakvinayak

Computer Science and Engineering student

Deep learning is a subpart of machine learning and artificial intelligence which is also known as deep neural network this networks capable of learning unsupervised from provided data which is unorganized or unlabeled. today, we will implement a neural network in 6 easy steps using TensorFlow to classify handwritten digits.

Modules required :

NumPy:

``\$ pip install numpy ``

Matplotlib:

``\$ pip install matplotlib ``

Tensorflow:

``\$ pip install tensorflow ``

## Steps to follow:

Step 1 : Importing all dependence

``````import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt``````

Step 2 : Import data and normalize it

``````mnist = tf.keras.datasets.mnist

x_train = tf.keras.utils.normalize(x_train,axis=1)
x_test = tf.keras.utils.normalize(x_test,axis=1)``````

Step 3 : view data

``````def draw(n):
plt.imshow(n,cmap=plt.cm.binary)
plt.show()

draw(x_train[0])``````

Step 4 : make a neural network and train it

``````#there are two types of models
#sequential is most common

model = tf.keras.models.Sequential()

#reshape

loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
model.fit(x_train,y_train,epochs=3)
``````

Step 5 : check model accuracy and loss

``````val_loss,val_acc = model.evaluate(x_test,y_test)
print("loss-> ",val_loss,"\nacc-> ",val_acc)``````

Step 6 : prediction using model

``````predictions=model.predict([x_test])
print('lable -> ',y_test[2])
print('prediction -> ',np.argmax(predictions[2]))

draw(x_test[2])``````

Join Hacker Noon