RECOGNIZING HANDWRITTEN DIGITS USING SCIKIT-LEARN

Swetha Sreenivasan
3 min readDec 1, 2020

Here we are going to see about how the scikit-learn is used in recognizing handwritten digits.

Scikit-learn is a free machine learning library for Python. It features various algorithms like support vector machine, random forests, and k-neighbors, and it also supports Python numerical and scientific libraries like NumPy and SciPy.

four-step modeling pattern in scikit-learn:
1. Import the model
2. Create instance
3. Training the model
4. Predicting the new label data

Before modeling the data prepare and split the data for train and test.

I imported the inbuilt dataset from the sklearn.

IMPORT THE REQUIRED LIBRARIES AND THE DATASET

CREATE AN INSTANCE FOR THE DATASET:

TO FIND HOW MANY ROWS AND COLUMNS USE SHAPE() METHOD:

VISUALIZING:

TRAIN SPLIT AND TEST SPLIT:

Here I split 80% of the data for train and 20% for test. Once we train our model it will recognize our new data.

USE MACHINE LEARNING ALGORITHM TO RECOGNIZE THE IMAGE:

You can use algorithm as per your choice. I’m using the support vector classifier. This algorithm comes under the supervised classification problem.

CREATING INSTANCE FOR THE MODEL

TRAINING THE INSTANCE MODEL:

PREDICTING THE NEW DATA

Once after the model data is trained use the predict method to predict the new data.

Check whether the train data and the prediction are same.

ACCURACY

To find the performance of the model import required method from the Metrics library. Metrics library has a lot of methods to calculate the accuracy such as Precision,Recall,F1-score etc.,

Here I’m going to use the Accuracy score method to calculate the performance of the model.

REPORT

Here I got 95 percent accuracy which means the model predicted 95% correctly. You can use the metrics as per your choice.

CONCLUSION

From this blog we learned how to use the sci-kit learn to recognize the hand written digits. Hope it is useful for you all. We may discuss about some other packages in another blog. If you find any mistake, please let me know. Thank you. Have a nice day.

--

--