Recognizing Handwritten Digits with Python


Everyday, developers are working hard on machines to make them more smart and intelligent by using machine learning and deep learning techniques so that they can perform tasks similar to humans. With the help of these techniques human effort can be reduced in recognizing, learning, predictions and many other areas.

The ability of computers to recognize human handwritten digits is known as handwritten digit recognition from sources such as paper documents, images, touch-screens etc.

In this article you will discover how to develop a deep learning model to achieve high performance on the handwritten digit recognition task using the MNIST dataset.

Problem Statement:

It is easy for the human to perform a task accurately by practicing it repeatedly and memorizing it for the next time. Human brain can process and analyse images easily. Also, recognize the different elements present in the images.

The challenge in handwritten digit recognition is mainly caused by the writing style variations of every single individual. So, it is not easy for the machine to recognize the handwritten digits accurately like the humans do. Hence, robust feature extraction is very important to improve the performance of machines.

MNIST Dataset:

The MNIST dataset (Modified National Institute of Standards and Technology) is a large dataset of handwritten digits that is widely used for training and testing in the field of machine learning and deep learning.

The MNIST dataset contains 70,000 training images and 10,000 testing images of handwritten digits from zero to nine(0 to 9). So, the MNIST dataset has 10 different classes. Each image is represented as a 28×28 matrix where each cell contains grayscale pixel value.

So, Let’s Start :

  1. Importing the Libraries:

2. Loading the MNIST dataset .This may take some time as data set is too large.

3. Printing the handwritten Digits from the Data set.

4. Splitting the data set into Training set and Test set.

5. Now we will Apply Logistic Regression to our Training set and will predict the score of our model. After applying Logistic Regression we will get error message just ignore it as our data set is too large it exceeds the MAX limit.

6. Most interesting part Prediction of Digits. I am attaching some of Digit predictions of the Model.


7. Making the Confusion Matrix of our Model.


The source code of this is available on my github repository.

For any queries related to my project contact me over my email id:

Closing Note: I hope this blog will help you to build your own Handwritten Digit Recognizing system.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store