SlideShare a Scribd company logo
Machine Learning Course Project
Optical Character Recognition (OCR)
Paper Title : Handwritten Digit Recognition
Submitted by:
2017-EE-02 Mehrunisa Ashraf
2017-EE-07 Hamda Anees
Supervised by:
Sir Kashif Javad
Department of Electrical Engineering
University of Engineering and Technology Lahore
Acknowledgments
We wish to express our gratitude to Dr. Kashif Javad, Professor Associate at Department of
Electrical Engineering for his remarkable supervision. I thank him for his relentless support,
patience, and encouragement. that led to the success of this project. I am also very thankful to
the other officials and supervisors who rendered their help during the period of the project work.
Sir K.M.Hassan
(Chairman Electrical Department)
i
Abstract
Handwritten digit recognition has recently been of very interest among the researchers because
of the evolution of various Machine Learning, Deep Learning and Computer Vision algorithms.
In this paper, the author has compared the results of some of the most widely used Machine
Learning Algorithms such as Support Vector Machine (SVM), K-Nearest Neighbours (KNN)
Random Forest Classifier (RFC); with Deep Learning algorithm such as Multilayer Convo-
lutional Neural-Network (CNN) using Keras with Theano and Tensorflow. However, in our
project we will only be comparing the result of the techniques of simple Machine Learning al-
gorithms and would not be covering the Deep Learning Techniques. The algorithms will be
trained and tested on the same data to draw a comparison between the simple Machine Learning
Techniques. Using the algorithms, an accuracy of 97.84% using SVM, 96.72% using KNN,
96.91% using RFC, was achieved. The paper was implemented on a CPU. Additional accuracy
can be achieved by reducing training and testing time, with the use of a GPU. Through GPU,
we get much parallel processing and attain much better computation results.
Key Words:- Machine Learning, Deep Learning, Computer Vision, Support Vector Machine,
K- Nearest Neighbour, Random Forest Classifier, Multi-Convolutional Neural Network, Keras
Contents
Acknowledgments i
Abstract ii
List of Figures v
List of Tables vi
1 Motivation & Objective 1
2 Problem Statement 2
3 Introduction 3
3.1 Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Current State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.3 Goal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 Literature Review 5
4.1 Project Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.2 Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.3 Support Vector Machine (SVM) . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.4 Random Forest Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.5 K-Nearest Neighbour Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 6
5 Methodology 8
5.1 Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
5.2 Machine Learning Techniques:- . . . . . . . . . . . . . . . . . . . . . . . . . 8
5.3 Support Vector Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.4 Random forest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.5 KNN Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6 Implementation of the Learning Techniques 15
6.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
6.2 Codes for Machine Learning Algorithm . . . . . . . . . . . . . . . . . . . . . 15
6.2.1 Code for KNN Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 16
6.2.2 Code for SVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.2.3 Code for Random Forest Classifier . . . . . . . . . . . . . . . . . . . . 20
iii
Table of Content iv
7 Results & Observation 23
7.1 Evaluation Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.2 Output of KNN Classification . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7.3 Output of SVM Classification . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.4 Output of Random Forest Classification . . . . . . . . . . . . . . . . . . . . . 29
7.5 Confusion matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.6 Machine Learning Accuracy & Test Error Comparison . . . . . . . . . . . . . 33
7.7 Result and Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
7.8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
References 35
List of Figures
5.1 Sample images of MNIST Dataset . . . . . . . . . . . . . . . . . . . . . . . . 8
5.2 SVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.3 Hyperplanes SVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.4 SVM Parameter Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5.5 RFC Parameter Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.6 N-Estimators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.1 KNN-Confusion Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
7.2 Validation Data Confusion Matrix for KNN . . . . . . . . . . . . . . . . . . . 25
7.3 Test Images for KNN Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 25
7.4 SVM-Confusion Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
7.5 Validation Data Confusion Matrix for SVM . . . . . . . . . . . . . . . . . . . 27
7.6 Test Data Confusion Matrix for SVM . . . . . . . . . . . . . . . . . . . . . . 28
7.7 Test Images for SVM Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 28
7.8 RFC-Confusion Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7.9 Validation Data Confusion Matrix for RFC . . . . . . . . . . . . . . . . . . . . 30
7.10 Test Data Confusion Matrix for RFC . . . . . . . . . . . . . . . . . . . . . . . 30
7.11 Test Images for RFC Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.12 KNN-Evaluation Metric for Test Images . . . . . . . . . . . . . . . . . . . . . 32
7.13 SVM-Evaluation Metric for Test Images . . . . . . . . . . . . . . . . . . . . . 32
7.14 RFC-Evaluation Metric for Test Images . . . . . . . . . . . . . . . . . . . . . 33
v
List of Tables
7.1 Accuracy Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
7.2 Test Error Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
vi
Chapter 1
Motivation & Objective
This paper is conducted by using Machine learning concepts. Before going deep into the topic,
we must know about some of these concepts.
Machine Learning may be a method which trains the machine to try to to the work by itself
with none human interaction. At a high level, machine learning is that the process of teach-
ing a computing system on the way to make accurate predictions when fed the info . Those
predictions will be the output. There are many sub-branches in machine learning like Neural
Networking, Deep Learning, etc. Among these, Deep Learning is considered to be the most
popular sub-branch of Machine Learning.
Initially, the idea of Machine Learning has come into existence during the 1950s, with the def-
inition of perception. It is the first machine which was capable of sensing learning. Further,
there was multilayer perceptron in the 1980s, with a limited number of hidden layers. However,
the concept of perceptron was not in usage because of its very limited learning capability. Af-
ter many years, in the early 2000s, a new concept called Neural Networks came into existence
with many hidden layers. The emergence of neural networks, brought many machine learning
concepts like deep learning into creation. Because of these multiple levels of representation
phenomenon, it has become easy to learn and recognize machines. The human brain is con-
sidered as a reference to build deep learning concepts, as the human brain similarly processes
information in multiple layers.
A human can easily solve and recognize any problem, but this is not the same in the case of
a machine. Many techniques or methods should be implemented to work as a human. Apart
from all the advancements that have been made in this area, there is still a significant research
gap that needs to be filled.
1
Chapter 2
Problem Statement
Handwritten character recognition is one among the practically important issues in pattern
recognition applications. The applications of digit recognition includes in postal mail sorting,
check processing, form data entry, etc. The heart of the matter lies within the power to develop
an efficient algorithm which will recognize handwritten digits and which is submitted by users
by the way of a scanner, tablet, and other digital devices. This paper presents an approach to a
state-of-art handwritten digit recognition based on different machine learning techniques. The
main objective of this paper[3] is to ensure effective and reliable approaches for recognition
of handwritten digits. Several machines learning algorithm namely, Support Vector Machine
(SVM), Random Forest Classifier (RFC),and K-Nearest Neighbour (KNN) has been used to
achieve high performance on the digit string recognition problem.
2
Chapter 3
Introduction
Handwritten digits recognition has been a well-researched subarea within the sector of AI, that is
concerned with learning models to differentiate handwritten digits from a good sort of sources.
It is one among the foremost important issues in data processing , machine learning, pattern
recognition along side many other disciplines of AI .The main application of machine learning
methods over the last decade has determined efficacious in conforming decisive systems which
are competing to human performance and which accomplish far improved than manually written
classical AI systems used in the beginnings of optical character recognition technology.
3.1 Challenges
The challenge in handwritten character recognition is mainly caused by the large variation of
individual writing styles because distinct community may use diverse style of handwriting, and
control to draw the similar pattern of the characters. Hence, robust feature extraction is ex-
tremely important to enhance the performance of a handwritten character recognition system.
3.2 Current State
Nowadays handwritten digit recognition has obtained lot of concentration in the area of pattern
recognition system sowing to its application in diverse fields. In next days, character recognition
system might serve as a cornerstone to initiate paperless surroundings by digitizing and process-
ing existing paper documents. Handwritten digit dataset are vague in nature because there may
not always be sharp and perfectly straight lines.
3.3 Goal
The main goal in digit recognition is feature extraction is to get rid of the redundancy from the
info and gain a simpler embodiment of the word image through a group of numerical attributes.
It deals with extracting most of the essential information from image data . In addition the
curves aren’t necessarily smooth just like the printed characters. Furthermore, characters dataset
are often drawn in several sizes and therefore the orientation which are always alleged to be
written on a suggestion in an upright or downright point. Accordingly, an efficient handwritten
3
List of Tables 4
recognition system are often developed by considering these limitations. It is quiet exhausting
that sometimes to spot hand written characters because it are often seen that the majority of the
citizenry can’t even recognize their own written scripts. Hence, there exists constraint for user
to write down apparently for recognition of handwritten documents.
Pattern recognition along side Image processing plays compelling role within the area of hand-
written character recognition. The study, describes numerous types of classification of feature
extraction techniques like structural feature based methods, statistical feature based methods
and global transformation techniques.
Chapter 4
Literature Review
4.1 Project Overview
The paper [3] proposes a state-of-art handwritten digit recognition system. The Author has com-
pared the results of some of the most widely used Machine Learning Algorithms such as Support
Vector Machine (SVM), K-Nearest Neighbours (KNN) Random Forest Classifier (RFC). The
algorithms have been trained and tested on the same data to draw a comparison between the
simple Machine Learning Techniques.
4.2 Machine Learning
According to Arthur Samuel [1], “Machine learning is a subfield of computer science which
gives computers the ability to learn without being explicitly programmed”[18]. This study helps
in predicting and learning from the data imported with the help of algorithms implemented. Ma-
chine learning is used where there is difficulty in programming tasks instead machine learning
algorithms are used to achieve the task. Machine learning concepts are classified into three
categories:
• Supervised Learning
• Unsupervised Learning
• Reinforcement Learning
Supervised Learning:
Consider, a dataset is given as input and assumptions can be made on the output data how it
looks like. In supervised learning, there’s a relationship between the input data and the output
data. The output can be predicted with the input given.
5
List of Tables 6
Unsupervised Learning:
Unsupervised learning is an approach where the algorithm has to identify the hidden patterns in
the given input. So, the algorithm works without any guidance as the input data is not labeled or
classified.
Reinforcement Learning:
Reinforcement learning is a suitable action to maximize reward in a particular situation. It is to
find the best possible behavior or path it should take in a specific situation.
In this paper, we will be investigating the performance of few selected methods or algorithms
namely Support Vector Machine, Random Forest Classifier and K-Nearest Neighbour.
4.3 Support Vector Machine (SVM)
Support Vector Machine (SVM) was introduced by introduced by Boser, Guyon, and Vapnik
in 1992. It is a core part of machine learning methods. A support vector machine (SVM) is a
supervised learning algorithm that can be used for binary classification or regression and even
it belongs to the family of a linear classifier. In other words, SVM is a popular application and
it is used in natural language processing, speech recognition, image recognition, and computer
vision. It constructs an optimal hyperplane for the decisions and the two margins separate action
between the two classes in the data is maximized. It refers to a small subset of the training
observation and used to support the optimal location of the decisions. In the process regression
and classification prediction tools and take care that the algorithm does not lead to overfitting.
4.4 Random Forest Algorithm
Random forest, like its name implies, consists of an outsized number of individual decision trees
that operate as an ensemble. Each [4] individual tree within the random forest spits out a cate-
gory prediction and therefore the class with the foremost votes becomes our model’s prediction.
The prediction is formed by accumulating the predictions of the ensemble by superiority voting
for classification. It returns generalization error rate and is stronger to noise. Still, almost like
most classifiers, RF can also suffer from the curse of learning from an intensely imbalanced
training data set. Since it’s constructed to mitigate the general error rate, it’ll tend to focus more
on the prediction efficiency of the bulk class, which repeatedly leads to poor accuracy for the
minority class.
4.5 K-Nearest Neighbour Algorithm
The k-nearest neighbors algorithm (k-NN) may be a non-parametric machine learning method
first developed by Evelyn Fix and Joseph Hodges in 1951, and later expanded by Thomas Cover.
It is used for classification and regression. In both cases, the input consists of the k closest train-
ing examples in feature space. The output depends on whether k-NN is employed for classifica-
tion or regression:
• In k-NN classification, the output is a class membership. An object is assessed by a
plurality vote of its neighbors, with the thing being assigned to the category commonest
List of Tables 7
among its k nearest neighbors (k may be a positive integer, typically small). If k = 1, then
the thing is just assigned to the category of that single nearest neighbor.
• In k-NN regression, the output is that the property value for the thing . This value is that
the average of the values of k nearest neighbors.
Chapter 5
Methodology
We have used simple machine learning techniques to predict the digits. Since this is a compara-
tive study hence we have tested out some of the most widely used Machine Learning Algorithms
such as Support Vector Machine (SVM), K-Nearest Neighbours (KNN) Random Forest Classi-
fier (RFC) and have compared the accuracy of each of the techniques.
5.1 Dataset
In our experiment we have used MNIST Handwritten digits dataset, a subset of a larger set
NIST.[6] It consists of a database of 70,000 handwritten digits, divided into 60,000 model train-
ing images and 10,000 images for the evaluation of the model. It contains images of digits
taken from a variety of scanned documents, normalized in size and centered. This makes it
an excellent dataset for evaluating models, allowing the developer to focus on the machine
learning with very little data cleaning or preparation required. Each image is a 28 by 28
pixel square (784 pixels total) in order to get better accuracy and distinction between black
and white pixels in the image. The dataset can be easily accessed from the link given below:
http://yann.lecun.com/exdb/mnist/
FIGURE 5.1: Sample images of MNIST Dataset
5.2 Machine Learning Techniques:-
• KNN
• RFC
• SVM
8
List of Tables 9
5.3 Support Vector Machine
A machine learning algorithm,[5] support vector machine algorithm is to seek out a hyperplane
in an N-dimensional space (N — the amount of features) that distinctly classifies the info points.
It’s basically to separate the 2 classes of knowledge points, there are many possible hyperplanes
that would be chosen. Our objective is to seek out a plane that has the utmost margin that is the
distance between data points of both classes. Maximizing the margin distance provides some
reinforcement in order that future data points are often classified with more confidence.
FIGURE 5.2: SVM
Hyperplanes and Support Vectors
To classify the info points we use decision boundaries that are called hyperplanes. Data points
falling on either side of the hyperplane are often attributed to different classes. They will [5] be
classified as positive and negative regions on the edges of hyperplane. Also, the dimension of the
hyperplane depends upon the amount of features. Once we have the amount of inputs equals to
2, the hyperplane is simply a line and just in case of three input features it becomes a plane in two
dimension but it becomes difficult to predict the hyperplane when number of features increases.
FIGURE 5.3: Hyperplanes SVM
List of Tables 10
The points which are closer to the hyperplanes are referred to as Support vectors which in-
fluence the position and orientation of the hyperplane. Support vectors as you’ll see in picture
are deciding the margin. When the position of support vectors changes, the margin also changes.
Large Margin Intuition
In logistic regression, we take the output of the linear function and squash the worth within the
range of [0, 1] using the sigmoid function. If the squashed value is bigger than a threshold value
(0.5) we assign it a label 1, else we assign it a label 0. In SVM, we take the output of the linear
function and if that output is bigger than 1, we identify it with one class and if the output is -1,
we identify is with another class. Since the edge values are changed to 1 and -1 in SVM, we
obtain this reinforcement range of values ([-1, 1]) which acts as margin.
Support Vector Machine (SVM) parameters in code
FIGURE 5.4: SVM Parameter Code
Steps to follow:
• Import Library
• Train data
• Test data
• Various options related to SVM training; like changing kernel, gamma and C value.
• Create the model
• model¡-svm(Target Predictor1+Predictor2+Predictor3, data=Train,
kernel=’linear/polynomial’,gamma=0.1,cost=100)
• Predict Output
Tuning of SVM Parameters
• The kernel parameter can be one from “Linear”,”Poly”,”rbf” etc.
• Gamma value can be tuned by setting the “Gamma” parameter.
• C value in Python is tuned by the “Cost” parameter in R.
List of Tables 11
Pros and Cons associated with SVM
• Pros:
• Effective when number of dimension is greater than number of samples.
• Effective in high dimensional spaces.
• Efficient with a clear margin of separation.
• Memory efficient because of using support vectors.
• Cons:
• Its performance gets effected due to noise data when target classes are overlapping.
• Probability estimations are calculated by expensive five fold cross validation in it.
• Performance gets effected due to large data set which demands more time in training.
Conclusion:
Support Vector Machine is an elegant and powerful supervised machine learning algorithm.
5.4 Random forest
Another machine learning algorithm is Random [5] forests or random decision forests which
are an ensemble learning method for classification, regression and other tasks that operate by
constructing a multitude of decision trees at training time and outputting the class that is the
mode of the classes or mean/average prediction of the individual trees.
To make better model:
1. It should be having Features with predictive power.
2. No (low)-correlation between the trees of the forest.
3. A model has a big impact of the features we select and the hyper-parameters we choose.
Random Forest Hyperparameters:
• max-depth
• min-sample-split
• max-leaf-nodes
• min-samples-leaf
List of Tables 12
• n-estimators
• max-sample (bootstrap sample)
• max-features
FIGURE 5.5: RFC Parameter Code
Random Forest Hyperparameters in this code:
N-Estimators:
N-estimators determines the number of trees in forests.In this graph, we can clearly see that the
performance of the model sharply increases and then stagnates at a certain level:
FIGURE 5.6: N-Estimators
Trend shows that with a large number of estimators in a random forest model the results are not
best. Although it will not degrade the model, it can save you the computational complexity and
prevent the use of a fire extinguisher on your CPU!
N-jobs:
This parameter is used to specify how many concurrent [5] processes or threads should be used
for routines that are parallelized with joblib. N-jobs is an integer, specifying the maximum num-
ber of concurrently running workers. If 1 is given, no joblib parallelism is used at all, which is
useful for debugging. If set to -1, all CPUs are used. For n-jobs below -1, (n-cpus + 1 + n-jobs)
List of Tables 13
are used.
N-jobs is none by default, which means unset; it will generally be interpreted as n-jobs=1, unless
the current joblib. Parallel backend context specifies otherwise.
Conclusion:
The random forest is a classification algorithm consisting of many decisions trees. It uses bag-
ging and feature randomness when building each individual tree to try to create an uncorrelated
forest of trees whose prediction is more accurate than that of any individual tree.
5.5 KNN Algorithm
K nearest neighbors is also a machine learning algorithm that stores all available cases and clas-
sifies new cases by a majority vote of its k neighbors. This algorithms segregates unlabeled data
points into well-defined groups.
How to select appropriate k value?
Determining the value of k plays a significant role in determining the efficacy of the model.
Thus, selection of k will determine how well the data can be utilized to generalize the results of
the kNN algorithm. A large k value has benefits which include reducing the variance due to the
noisy data; the side effect being developing a bias due to which the learner tends to ignore the
smaller patterns which may have useful insights.
KNN Algorithm- Pros and Cons
• Pros:
• Highly unbiased and simple algorithm in nature.
• No prior assumption of the underlying data.
• It is easy to implement and has gained good popularity.
• Cons:
• If we take a deeper look, this doesn’t create a model since there’s no abstraction process
involved.
• The prediction time is pretty high in this algorithm, and a lazy learner it is.
• Building this algorithm requires time to be invested in data preparation.
Steps to Follow:
• Data collection
List of Tables 14
• Preparing and exploring the data
• Normalizing numeric data
• Creating training and test data set
• Training a model on data
• Evaluate the model performance
• Improve the performance of the model
Chapter 6
Implementation of the Learning
Techniques
The paper is implemented by following the following steps:-
6.1 Procedure
1. Write the code for KNN, RFC and SVM. (The screenshots of the code is given in the
section below)
2. Open command prompt(Write cmd in search bar).
3. Provide the directory to the folder where the code is written, by writing (cd Folder) in
command prompt.
4. Install all the following requirements in your command prompt.
5. Requirements:-
• Python 3.5 + (pip install python==3.5)
• Scikit-Learn (pip install scikit-learn)
• Numpy (pip install numpy)
• Matplotlib (pip install matplotlib)
6. Now, run the python files on which you have written the code (python knn.py), (python
svm.py) or (python rfc.py).
After Running the python files, you will receive all the print statements in the ”summary.log”
file.
6.2 Codes for Machine Learning Algorithm
The following are the codes for the implementation of the machine learning algorithms (as
discussed in the paper).
15
List of Tables 16
6.2.1 Code for KNN Algorithm
List of Tables 17
List of Tables 18
6.2.2 Code for SVM
List of Tables 19
List of Tables 20
6.2.3 Code for Random Forest Classifier
List of Tables 21
List of Tables 22
Chapter 7
Results & Observation
While implementing the algorithm model on the training data, the results are observed on the
test data, special focus on the accuracy of the model. With the calculated accuracy and precision,
we can comprehend the efficiency of the training model.
7.1 Evaluation Metric
In this paper, we have evaluated the machine learning techniques (as mentioned in the method-
ology), upon the below given criteria:
• Accuracy
• Precision
• Recall
• F1-Score
7.2 Output of KNN Classification
The image below shows a step-by-step output of the KNN Classifier. We have obtained an
accuracy of 97.43% on the trained classifier,and on the prediction labels dataset, we got an
accuracy of 96.72%.
23
List of Tables 24
FIGURE 7.1: KNN-Confusion Matrix
List of Tables 25
FIGURE 7.2: Validation Data Confusion Matrix for KNN
FIGURE 7.3: Test Images for KNN Algorithm
List of Tables 26
7.3 Output of SVM Classification
The following image shows a step-by-step output of the SVM classifier. We have obtained an
accuracy of 97.79% on trained classifier and 97.84% on prediction labels dataset.
List of Tables 27
FIGURE 7.4: SVM-Confusion Matrix
FIGURE 7.5: Validation Data Confusion Matrix for SVM
List of Tables 28
FIGURE 7.6: Test Data Confusion Matrix for SVM
FIGURE 7.7: Test Images for SVM Algorithm
List of Tables 29
7.4 Output of Random Forest Classification
The following image shows a step-by-step output of the RFC classifier. We obtained an accuracy
of 96.78% on trained classifier and 96.91% on prediction labels dataset. newline
FIGURE 7.8: RFC-Confusion Matrix
List of Tables 30
FIGURE 7.9: Validation Data Confusion Matrix for RFC
FIGURE 7.10: Test Data Confusion Matrix for RFC
List of Tables 31
FIGURE 7.11: Test Images for RFC Algorithm
7.5 Confusion matrix
In all the outputs of the classifiers, we see a confusion matrix. A confusion matrix defines a
specific table that allows the visualization of the performance of an algorithm by providing the
accuracy corresponding to each of the input and output classes.[2]
List of Tables 32
FIGURE 7.12: KNN-Evaluation Metric for Test Images
FIGURE 7.13: SVM-Evaluation Metric for Test Images
List of Tables 33
FIGURE 7.14: RFC-Evaluation Metric for Test Images
Accuracy RFC KNN SVM
Trained Classifier 96.78% 97.43% 97.79%
Test Images 96.91% 96.72% 97.84%
TABLE 7.1: Accuracy Comparison
7.6 Machine Learning Accuracy & Test Error Comparison
We have seen the working of three of the most commonly used Machine Learning algorithms
used for Handwritten Digit recognition. The method of Random Forest Classifier is able to
recognize the digits 96.91% correctly. Using the K Nearest Neighbors, we are able to get an ac-
curacy of 96.72% for the digit recognition. Similarly, for the SVM classifier, we get an accuracy
of 97.84% for the digit recognition.
List of Tables 34
Model Test Error Rate
KNN Classifier 3.28%
Random Forest Classifier 3.09%
Support Vector Machine 2.16%
TABLE 7.2: Test Error Comparison
7.7 Result and Analysis
Hence, we can conclude, after implementing the algorithm on the training data and test data;
compared to all of the algorithms, SVM succeeded in achieving better accuracy (after that is
RFC and lastly, KNN). The main reason for the better performance of the SVM than any other
algorithms, is that SVM is developed to overcome the classification problems now recent stud-
ies are made on the use of SVM to overcome the regression issues as well. Moreover, while
implementing the following algorithms KNN algorithm took the longest time in predicting the
test instances. Hence Support Vector Machine (SVM) clearly leaves K-NN behind in terms of
efficiency in Prediction Time and also in terms of computation and memory load.
7.8 Conclusion
An implementation of Handwritten Digit Recognition has been implemented in this paper.Additionally,
some of the most widely used Machine Learning algorithms i.e. RFC, KNN and SVM have been
trained and tested on the same data to draw a comparison between the simple Machine Learn-
ing Techniques. Using the algorithms, an accuracy of 97.84% using SVM, 96.72% using KNN,
96.91% using RFC, was achieved. Also, the current implementation is done only using the CPU.
For additional accuracy, reduced training and testing time, the use of GPU is required. Using
GPU we will achieve parallel computing and attain much better results.
References
[1] Akkireddy Challa. ” automatic handwritten digit recognition on document images using
machine learning methods”,jan 2019,blekinge institute of technology, karlskrona, sweden.
Accessed Jan 03, 2021.
[2] CM. ” confusion matrix”. Accessed Jan 03, 2021.
[3] Anuj Dutt and Aash Dutt. ” handwritten digit recognition using deep learning”, volume-6,
issue-7, july 2017, issn: 2278 – 1323. Accessed Jan 03, 2021.
[4] Angona Sarker Masud Rana Abdullah Al Jobair S M Shamim, Mohammad Badrul
Alam Miah. ”handwritten digit recognition using machine learning algorithms”,global
journal of computer science and technology: Dneural artificial intelligence, vol-18,issue-
1,2018,. Accessed Jan 03, 2021.
[5] Mayank Semwal Vipul Malhotra. ” detect malicious benign websites using machine learn-
ing”. Accessed Jan 03, 2021.
[6] Christopher J.C. Burges Yann LeCun, Corinna Cortes. ” the mnist database of handwritten
digits”. Accessed Jan 03, 2021.
35

More Related Content

What's hot

Machine Learning
Machine LearningMachine Learning
Machine Learning
Bhupender Sharma
 
Machine Learning presentation.
Machine Learning presentation.Machine Learning presentation.
Machine Learning presentation.butest
 
IRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
IRJET- Sentimental Analysis for Online Reviews using Machine Learning AlgorithmsIRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
IRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
IRJET Journal
 
ML Basics
ML BasicsML Basics
ML Basics
SrujanaMerugu1
 
Heart disease classification
Heart disease classificationHeart disease classification
Heart disease classification
SnehaDey21
 
Lecture #1: Introduction to machine learning (ML)
Lecture #1: Introduction to machine learning (ML)Lecture #1: Introduction to machine learning (ML)
Lecture #1: Introduction to machine learning (ML)butest
 
Applications of Machine Learning
Applications of Machine LearningApplications of Machine Learning
Applications of Machine Learning
Department of Computer Science, Aalto University
 
Machine learning
Machine learningMachine learning
Machine learning
Rohit Kumar
 
Machine learning
Machine learning Machine learning
Machine learning
Saurabh Agrawal
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Rahul Jain
 
Machine learning_ Replicating Human Brain
Machine learning_ Replicating Human BrainMachine learning_ Replicating Human Brain
Machine learning_ Replicating Human Brain
Nishant Jain
 
Building Azure Machine Learning Models
Building Azure Machine Learning ModelsBuilding Azure Machine Learning Models
Building Azure Machine Learning Models
Eng Teong Cheah
 
Scikit Learn Tutorial | Machine Learning with Python | Python for Data Scienc...
Scikit Learn Tutorial | Machine Learning with Python | Python for Data Scienc...Scikit Learn Tutorial | Machine Learning with Python | Python for Data Scienc...
Scikit Learn Tutorial | Machine Learning with Python | Python for Data Scienc...
Edureka!
 
Comparison of machine learning methods for breast cancer diagnosis
Comparison of machine learning methods for breast cancer diagnosisComparison of machine learning methods for breast cancer diagnosis
Comparison of machine learning methods for breast cancer diagnosis
Venkat Projects
 
Data Science Interview Questions | Data Science Interview Questions And Answe...
Data Science Interview Questions | Data Science Interview Questions And Answe...Data Science Interview Questions | Data Science Interview Questions And Answe...
Data Science Interview Questions | Data Science Interview Questions And Answe...
Simplilearn
 
Feature extraction for classifying students based on theirac ademic performance
Feature extraction for classifying students based on theirac ademic performanceFeature extraction for classifying students based on theirac ademic performance
Feature extraction for classifying students based on theirac ademic performance
Venkat Projects
 
Learning Methods in a Neural Network
Learning Methods in a Neural NetworkLearning Methods in a Neural Network
Learning Methods in a Neural Network
Saransh Choudhary
 
"An Introduction to Machine Learning and How to Teach Machines to See," a Pre...
"An Introduction to Machine Learning and How to Teach Machines to See," a Pre..."An Introduction to Machine Learning and How to Teach Machines to See," a Pre...
"An Introduction to Machine Learning and How to Teach Machines to See," a Pre...
Edge AI and Vision Alliance
 

What's hot (19)

Machine Learning
Machine LearningMachine Learning
Machine Learning
 
Machine Learning presentation.
Machine Learning presentation.Machine Learning presentation.
Machine Learning presentation.
 
IRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
IRJET- Sentimental Analysis for Online Reviews using Machine Learning AlgorithmsIRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
IRJET- Sentimental Analysis for Online Reviews using Machine Learning Algorithms
 
ML Basics
ML BasicsML Basics
ML Basics
 
Heart disease classification
Heart disease classificationHeart disease classification
Heart disease classification
 
Lecture #1: Introduction to machine learning (ML)
Lecture #1: Introduction to machine learning (ML)Lecture #1: Introduction to machine learning (ML)
Lecture #1: Introduction to machine learning (ML)
 
Applications of Machine Learning
Applications of Machine LearningApplications of Machine Learning
Applications of Machine Learning
 
Machine learning
Machine learningMachine learning
Machine learning
 
Machine learning
Machine learning Machine learning
Machine learning
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
Machine learning_ Replicating Human Brain
Machine learning_ Replicating Human BrainMachine learning_ Replicating Human Brain
Machine learning_ Replicating Human Brain
 
Building Azure Machine Learning Models
Building Azure Machine Learning ModelsBuilding Azure Machine Learning Models
Building Azure Machine Learning Models
 
Scikit Learn Tutorial | Machine Learning with Python | Python for Data Scienc...
Scikit Learn Tutorial | Machine Learning with Python | Python for Data Scienc...Scikit Learn Tutorial | Machine Learning with Python | Python for Data Scienc...
Scikit Learn Tutorial | Machine Learning with Python | Python for Data Scienc...
 
Comparison of machine learning methods for breast cancer diagnosis
Comparison of machine learning methods for breast cancer diagnosisComparison of machine learning methods for breast cancer diagnosis
Comparison of machine learning methods for breast cancer diagnosis
 
Machine learning
Machine learningMachine learning
Machine learning
 
Data Science Interview Questions | Data Science Interview Questions And Answe...
Data Science Interview Questions | Data Science Interview Questions And Answe...Data Science Interview Questions | Data Science Interview Questions And Answe...
Data Science Interview Questions | Data Science Interview Questions And Answe...
 
Feature extraction for classifying students based on theirac ademic performance
Feature extraction for classifying students based on theirac ademic performanceFeature extraction for classifying students based on theirac ademic performance
Feature extraction for classifying students based on theirac ademic performance
 
Learning Methods in a Neural Network
Learning Methods in a Neural NetworkLearning Methods in a Neural Network
Learning Methods in a Neural Network
 
"An Introduction to Machine Learning and How to Teach Machines to See," a Pre...
"An Introduction to Machine Learning and How to Teach Machines to See," a Pre..."An Introduction to Machine Learning and How to Teach Machines to See," a Pre...
"An Introduction to Machine Learning and How to Teach Machines to See," a Pre...
 

Similar to Machine Learning Project - Neural Network

Au anthea-ws-201011-ma sc-thesis
Au anthea-ws-201011-ma sc-thesisAu anthea-ws-201011-ma sc-thesis
Au anthea-ws-201011-ma sc-thesisevegod
 
Distributed Traffic management framework
Distributed Traffic management frameworkDistributed Traffic management framework
Distributed Traffic management framework
Saurabh Nambiar
 
Neural Networks on Steroids
Neural Networks on SteroidsNeural Networks on Steroids
Neural Networks on Steroids
Adam Blevins
 
Efficiency Optimization of Realtime GPU Raytracing in Modeling of Car2Car Com...
Efficiency Optimization of Realtime GPU Raytracing in Modeling of Car2Car Com...Efficiency Optimization of Realtime GPU Raytracing in Modeling of Car2Car Com...
Efficiency Optimization of Realtime GPU Raytracing in Modeling of Car2Car Com...
Alexander Zhdanov
 
A Seminar Report On NEURAL NETWORK
A Seminar Report On NEURAL NETWORKA Seminar Report On NEURAL NETWORK
A Seminar Report On NEURAL NETWORK
Sara Parker
 
outiar.pdf
outiar.pdfoutiar.pdf
outiar.pdf
ssusere02009
 
Final Report - Major Project - MAP
Final Report - Major Project - MAPFinal Report - Major Project - MAP
Final Report - Major Project - MAPArjun Aravind
 
Machine_Learning_Blocks___Bryan_Thesis
Machine_Learning_Blocks___Bryan_ThesisMachine_Learning_Blocks___Bryan_Thesis
Machine_Learning_Blocks___Bryan_ThesisBryan Collazo Santiago
 
Automatic Detection of Performance Design and Deployment Antipatterns in Comp...
Automatic Detection of Performance Design and Deployment Antipatterns in Comp...Automatic Detection of Performance Design and Deployment Antipatterns in Comp...
Automatic Detection of Performance Design and Deployment Antipatterns in Comp...
Trevor Parsons
 
Virtual Environments as Driving Schools for Deep Learning Vision-Based Sensor...
Virtual Environments as Driving Schools for Deep Learning Vision-Based Sensor...Virtual Environments as Driving Schools for Deep Learning Vision-Based Sensor...
Virtual Environments as Driving Schools for Deep Learning Vision-Based Sensor...
Artur Filipowicz
 
An Introduction to Computational Networks and the Computational Network Toolk...
An Introduction to Computational Networks and the Computational Network Toolk...An Introduction to Computational Networks and the Computational Network Toolk...
An Introduction to Computational Networks and the Computational Network Toolk...
Willy Marroquin (WillyDevNET)
 
Big Data and the Web: Algorithms for Data Intensive Scalable Computing
Big Data and the Web: Algorithms for Data Intensive Scalable ComputingBig Data and the Web: Algorithms for Data Intensive Scalable Computing
Big Data and the Web: Algorithms for Data Intensive Scalable Computing
Gabriela Agustini
 
Big data-and-the-web
Big data-and-the-webBig data-and-the-web
Big data-and-the-web
Aravindharamanan S
 

Similar to Machine Learning Project - Neural Network (20)

Au anthea-ws-201011-ma sc-thesis
Au anthea-ws-201011-ma sc-thesisAu anthea-ws-201011-ma sc-thesis
Au anthea-ws-201011-ma sc-thesis
 
main
mainmain
main
 
xlelke00
xlelke00xlelke00
xlelke00
 
Distributed Traffic management framework
Distributed Traffic management frameworkDistributed Traffic management framework
Distributed Traffic management framework
 
Neural Networks on Steroids
Neural Networks on SteroidsNeural Networks on Steroids
Neural Networks on Steroids
 
Thesis
ThesisThesis
Thesis
 
Efficiency Optimization of Realtime GPU Raytracing in Modeling of Car2Car Com...
Efficiency Optimization of Realtime GPU Raytracing in Modeling of Car2Car Com...Efficiency Optimization of Realtime GPU Raytracing in Modeling of Car2Car Com...
Efficiency Optimization of Realtime GPU Raytracing in Modeling of Car2Car Com...
 
A Seminar Report On NEURAL NETWORK
A Seminar Report On NEURAL NETWORKA Seminar Report On NEURAL NETWORK
A Seminar Report On NEURAL NETWORK
 
outiar.pdf
outiar.pdfoutiar.pdf
outiar.pdf
 
Final Report - Major Project - MAP
Final Report - Major Project - MAPFinal Report - Major Project - MAP
Final Report - Major Project - MAP
 
report
reportreport
report
 
Machine_Learning_Blocks___Bryan_Thesis
Machine_Learning_Blocks___Bryan_ThesisMachine_Learning_Blocks___Bryan_Thesis
Machine_Learning_Blocks___Bryan_Thesis
 
Automatic Detection of Performance Design and Deployment Antipatterns in Comp...
Automatic Detection of Performance Design and Deployment Antipatterns in Comp...Automatic Detection of Performance Design and Deployment Antipatterns in Comp...
Automatic Detection of Performance Design and Deployment Antipatterns in Comp...
 
Mak ms
Mak msMak ms
Mak ms
 
Virtual Environments as Driving Schools for Deep Learning Vision-Based Sensor...
Virtual Environments as Driving Schools for Deep Learning Vision-Based Sensor...Virtual Environments as Driving Schools for Deep Learning Vision-Based Sensor...
Virtual Environments as Driving Schools for Deep Learning Vision-Based Sensor...
 
thesis
thesisthesis
thesis
 
An Introduction to Computational Networks and the Computational Network Toolk...
An Introduction to Computational Networks and the Computational Network Toolk...An Introduction to Computational Networks and the Computational Network Toolk...
An Introduction to Computational Networks and the Computational Network Toolk...
 
Big Data and the Web: Algorithms for Data Intensive Scalable Computing
Big Data and the Web: Algorithms for Data Intensive Scalable ComputingBig Data and the Web: Algorithms for Data Intensive Scalable Computing
Big Data and the Web: Algorithms for Data Intensive Scalable Computing
 
Big data-and-the-web
Big data-and-the-webBig data-and-the-web
Big data-and-the-web
 
Sona project
Sona projectSona project
Sona project
 

More from HamdaAnees

Smart Crowd Analyzer.pptx
Smart Crowd Analyzer.pptxSmart Crowd Analyzer.pptx
Smart Crowd Analyzer.pptx
HamdaAnees
 
Database Website on Django
Database Website on DjangoDatabase Website on Django
Database Website on Django
HamdaAnees
 
Uber Corp
Uber CorpUber Corp
Uber Corp
HamdaAnees
 
Pakistan Constitution 1956
Pakistan Constitution 1956 Pakistan Constitution 1956
Pakistan Constitution 1956
HamdaAnees
 
Religious Hatred
Religious HatredReligious Hatred
Religious Hatred
HamdaAnees
 
UBER Corp
UBER CorpUBER Corp
UBER Corp
HamdaAnees
 
Illiteracy
IlliteracyIlliteracy
Illiteracy
HamdaAnees
 
Effective Body Language For Presentation Skills
Effective Body Language For Presentation SkillsEffective Body Language For Presentation Skills
Effective Body Language For Presentation Skills
HamdaAnees
 

More from HamdaAnees (8)

Smart Crowd Analyzer.pptx
Smart Crowd Analyzer.pptxSmart Crowd Analyzer.pptx
Smart Crowd Analyzer.pptx
 
Database Website on Django
Database Website on DjangoDatabase Website on Django
Database Website on Django
 
Uber Corp
Uber CorpUber Corp
Uber Corp
 
Pakistan Constitution 1956
Pakistan Constitution 1956 Pakistan Constitution 1956
Pakistan Constitution 1956
 
Religious Hatred
Religious HatredReligious Hatred
Religious Hatred
 
UBER Corp
UBER CorpUBER Corp
UBER Corp
 
Illiteracy
IlliteracyIlliteracy
Illiteracy
 
Effective Body Language For Presentation Skills
Effective Body Language For Presentation SkillsEffective Body Language For Presentation Skills
Effective Body Language For Presentation Skills
 

Recently uploaded

Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 

Recently uploaded (20)

Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 

Machine Learning Project - Neural Network

  • 1. Machine Learning Course Project Optical Character Recognition (OCR) Paper Title : Handwritten Digit Recognition Submitted by: 2017-EE-02 Mehrunisa Ashraf 2017-EE-07 Hamda Anees Supervised by: Sir Kashif Javad Department of Electrical Engineering University of Engineering and Technology Lahore
  • 2. Acknowledgments We wish to express our gratitude to Dr. Kashif Javad, Professor Associate at Department of Electrical Engineering for his remarkable supervision. I thank him for his relentless support, patience, and encouragement. that led to the success of this project. I am also very thankful to the other officials and supervisors who rendered their help during the period of the project work. Sir K.M.Hassan (Chairman Electrical Department) i
  • 3. Abstract Handwritten digit recognition has recently been of very interest among the researchers because of the evolution of various Machine Learning, Deep Learning and Computer Vision algorithms. In this paper, the author has compared the results of some of the most widely used Machine Learning Algorithms such as Support Vector Machine (SVM), K-Nearest Neighbours (KNN) Random Forest Classifier (RFC); with Deep Learning algorithm such as Multilayer Convo- lutional Neural-Network (CNN) using Keras with Theano and Tensorflow. However, in our project we will only be comparing the result of the techniques of simple Machine Learning al- gorithms and would not be covering the Deep Learning Techniques. The algorithms will be trained and tested on the same data to draw a comparison between the simple Machine Learning Techniques. Using the algorithms, an accuracy of 97.84% using SVM, 96.72% using KNN, 96.91% using RFC, was achieved. The paper was implemented on a CPU. Additional accuracy can be achieved by reducing training and testing time, with the use of a GPU. Through GPU, we get much parallel processing and attain much better computation results. Key Words:- Machine Learning, Deep Learning, Computer Vision, Support Vector Machine, K- Nearest Neighbour, Random Forest Classifier, Multi-Convolutional Neural Network, Keras
  • 4. Contents Acknowledgments i Abstract ii List of Figures v List of Tables vi 1 Motivation & Objective 1 2 Problem Statement 2 3 Introduction 3 3.1 Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3.2 Current State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3.3 Goal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 4 Literature Review 5 4.1 Project Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.2 Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4.3 Support Vector Machine (SVM) . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.4 Random Forest Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4.5 K-Nearest Neighbour Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 6 5 Methodology 8 5.1 Dataset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.2 Machine Learning Techniques:- . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.3 Support Vector Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.4 Random forest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5.5 KNN Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 6 Implementation of the Learning Techniques 15 6.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 6.2 Codes for Machine Learning Algorithm . . . . . . . . . . . . . . . . . . . . . 15 6.2.1 Code for KNN Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 16 6.2.2 Code for SVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 6.2.3 Code for Random Forest Classifier . . . . . . . . . . . . . . . . . . . . 20 iii
  • 5. Table of Content iv 7 Results & Observation 23 7.1 Evaluation Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 7.2 Output of KNN Classification . . . . . . . . . . . . . . . . . . . . . . . . . . 23 7.3 Output of SVM Classification . . . . . . . . . . . . . . . . . . . . . . . . . . 26 7.4 Output of Random Forest Classification . . . . . . . . . . . . . . . . . . . . . 29 7.5 Confusion matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 7.6 Machine Learning Accuracy & Test Error Comparison . . . . . . . . . . . . . 33 7.7 Result and Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 7.8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 References 35
  • 6. List of Figures 5.1 Sample images of MNIST Dataset . . . . . . . . . . . . . . . . . . . . . . . . 8 5.2 SVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3 Hyperplanes SVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.4 SVM Parameter Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5.5 RFC Parameter Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.6 N-Estimators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 7.1 KNN-Confusion Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 7.2 Validation Data Confusion Matrix for KNN . . . . . . . . . . . . . . . . . . . 25 7.3 Test Images for KNN Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 25 7.4 SVM-Confusion Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 7.5 Validation Data Confusion Matrix for SVM . . . . . . . . . . . . . . . . . . . 27 7.6 Test Data Confusion Matrix for SVM . . . . . . . . . . . . . . . . . . . . . . 28 7.7 Test Images for SVM Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 28 7.8 RFC-Confusion Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 7.9 Validation Data Confusion Matrix for RFC . . . . . . . . . . . . . . . . . . . . 30 7.10 Test Data Confusion Matrix for RFC . . . . . . . . . . . . . . . . . . . . . . . 30 7.11 Test Images for RFC Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 31 7.12 KNN-Evaluation Metric for Test Images . . . . . . . . . . . . . . . . . . . . . 32 7.13 SVM-Evaluation Metric for Test Images . . . . . . . . . . . . . . . . . . . . . 32 7.14 RFC-Evaluation Metric for Test Images . . . . . . . . . . . . . . . . . . . . . 33 v
  • 7. List of Tables 7.1 Accuracy Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 7.2 Test Error Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 vi
  • 8. Chapter 1 Motivation & Objective This paper is conducted by using Machine learning concepts. Before going deep into the topic, we must know about some of these concepts. Machine Learning may be a method which trains the machine to try to to the work by itself with none human interaction. At a high level, machine learning is that the process of teach- ing a computing system on the way to make accurate predictions when fed the info . Those predictions will be the output. There are many sub-branches in machine learning like Neural Networking, Deep Learning, etc. Among these, Deep Learning is considered to be the most popular sub-branch of Machine Learning. Initially, the idea of Machine Learning has come into existence during the 1950s, with the def- inition of perception. It is the first machine which was capable of sensing learning. Further, there was multilayer perceptron in the 1980s, with a limited number of hidden layers. However, the concept of perceptron was not in usage because of its very limited learning capability. Af- ter many years, in the early 2000s, a new concept called Neural Networks came into existence with many hidden layers. The emergence of neural networks, brought many machine learning concepts like deep learning into creation. Because of these multiple levels of representation phenomenon, it has become easy to learn and recognize machines. The human brain is con- sidered as a reference to build deep learning concepts, as the human brain similarly processes information in multiple layers. A human can easily solve and recognize any problem, but this is not the same in the case of a machine. Many techniques or methods should be implemented to work as a human. Apart from all the advancements that have been made in this area, there is still a significant research gap that needs to be filled. 1
  • 9. Chapter 2 Problem Statement Handwritten character recognition is one among the practically important issues in pattern recognition applications. The applications of digit recognition includes in postal mail sorting, check processing, form data entry, etc. The heart of the matter lies within the power to develop an efficient algorithm which will recognize handwritten digits and which is submitted by users by the way of a scanner, tablet, and other digital devices. This paper presents an approach to a state-of-art handwritten digit recognition based on different machine learning techniques. The main objective of this paper[3] is to ensure effective and reliable approaches for recognition of handwritten digits. Several machines learning algorithm namely, Support Vector Machine (SVM), Random Forest Classifier (RFC),and K-Nearest Neighbour (KNN) has been used to achieve high performance on the digit string recognition problem. 2
  • 10. Chapter 3 Introduction Handwritten digits recognition has been a well-researched subarea within the sector of AI, that is concerned with learning models to differentiate handwritten digits from a good sort of sources. It is one among the foremost important issues in data processing , machine learning, pattern recognition along side many other disciplines of AI .The main application of machine learning methods over the last decade has determined efficacious in conforming decisive systems which are competing to human performance and which accomplish far improved than manually written classical AI systems used in the beginnings of optical character recognition technology. 3.1 Challenges The challenge in handwritten character recognition is mainly caused by the large variation of individual writing styles because distinct community may use diverse style of handwriting, and control to draw the similar pattern of the characters. Hence, robust feature extraction is ex- tremely important to enhance the performance of a handwritten character recognition system. 3.2 Current State Nowadays handwritten digit recognition has obtained lot of concentration in the area of pattern recognition system sowing to its application in diverse fields. In next days, character recognition system might serve as a cornerstone to initiate paperless surroundings by digitizing and process- ing existing paper documents. Handwritten digit dataset are vague in nature because there may not always be sharp and perfectly straight lines. 3.3 Goal The main goal in digit recognition is feature extraction is to get rid of the redundancy from the info and gain a simpler embodiment of the word image through a group of numerical attributes. It deals with extracting most of the essential information from image data . In addition the curves aren’t necessarily smooth just like the printed characters. Furthermore, characters dataset are often drawn in several sizes and therefore the orientation which are always alleged to be written on a suggestion in an upright or downright point. Accordingly, an efficient handwritten 3
  • 11. List of Tables 4 recognition system are often developed by considering these limitations. It is quiet exhausting that sometimes to spot hand written characters because it are often seen that the majority of the citizenry can’t even recognize their own written scripts. Hence, there exists constraint for user to write down apparently for recognition of handwritten documents. Pattern recognition along side Image processing plays compelling role within the area of hand- written character recognition. The study, describes numerous types of classification of feature extraction techniques like structural feature based methods, statistical feature based methods and global transformation techniques.
  • 12. Chapter 4 Literature Review 4.1 Project Overview The paper [3] proposes a state-of-art handwritten digit recognition system. The Author has com- pared the results of some of the most widely used Machine Learning Algorithms such as Support Vector Machine (SVM), K-Nearest Neighbours (KNN) Random Forest Classifier (RFC). The algorithms have been trained and tested on the same data to draw a comparison between the simple Machine Learning Techniques. 4.2 Machine Learning According to Arthur Samuel [1], “Machine learning is a subfield of computer science which gives computers the ability to learn without being explicitly programmed”[18]. This study helps in predicting and learning from the data imported with the help of algorithms implemented. Ma- chine learning is used where there is difficulty in programming tasks instead machine learning algorithms are used to achieve the task. Machine learning concepts are classified into three categories: • Supervised Learning • Unsupervised Learning • Reinforcement Learning Supervised Learning: Consider, a dataset is given as input and assumptions can be made on the output data how it looks like. In supervised learning, there’s a relationship between the input data and the output data. The output can be predicted with the input given. 5
  • 13. List of Tables 6 Unsupervised Learning: Unsupervised learning is an approach where the algorithm has to identify the hidden patterns in the given input. So, the algorithm works without any guidance as the input data is not labeled or classified. Reinforcement Learning: Reinforcement learning is a suitable action to maximize reward in a particular situation. It is to find the best possible behavior or path it should take in a specific situation. In this paper, we will be investigating the performance of few selected methods or algorithms namely Support Vector Machine, Random Forest Classifier and K-Nearest Neighbour. 4.3 Support Vector Machine (SVM) Support Vector Machine (SVM) was introduced by introduced by Boser, Guyon, and Vapnik in 1992. It is a core part of machine learning methods. A support vector machine (SVM) is a supervised learning algorithm that can be used for binary classification or regression and even it belongs to the family of a linear classifier. In other words, SVM is a popular application and it is used in natural language processing, speech recognition, image recognition, and computer vision. It constructs an optimal hyperplane for the decisions and the two margins separate action between the two classes in the data is maximized. It refers to a small subset of the training observation and used to support the optimal location of the decisions. In the process regression and classification prediction tools and take care that the algorithm does not lead to overfitting. 4.4 Random Forest Algorithm Random forest, like its name implies, consists of an outsized number of individual decision trees that operate as an ensemble. Each [4] individual tree within the random forest spits out a cate- gory prediction and therefore the class with the foremost votes becomes our model’s prediction. The prediction is formed by accumulating the predictions of the ensemble by superiority voting for classification. It returns generalization error rate and is stronger to noise. Still, almost like most classifiers, RF can also suffer from the curse of learning from an intensely imbalanced training data set. Since it’s constructed to mitigate the general error rate, it’ll tend to focus more on the prediction efficiency of the bulk class, which repeatedly leads to poor accuracy for the minority class. 4.5 K-Nearest Neighbour Algorithm The k-nearest neighbors algorithm (k-NN) may be a non-parametric machine learning method first developed by Evelyn Fix and Joseph Hodges in 1951, and later expanded by Thomas Cover. It is used for classification and regression. In both cases, the input consists of the k closest train- ing examples in feature space. The output depends on whether k-NN is employed for classifica- tion or regression: • In k-NN classification, the output is a class membership. An object is assessed by a plurality vote of its neighbors, with the thing being assigned to the category commonest
  • 14. List of Tables 7 among its k nearest neighbors (k may be a positive integer, typically small). If k = 1, then the thing is just assigned to the category of that single nearest neighbor. • In k-NN regression, the output is that the property value for the thing . This value is that the average of the values of k nearest neighbors.
  • 15. Chapter 5 Methodology We have used simple machine learning techniques to predict the digits. Since this is a compara- tive study hence we have tested out some of the most widely used Machine Learning Algorithms such as Support Vector Machine (SVM), K-Nearest Neighbours (KNN) Random Forest Classi- fier (RFC) and have compared the accuracy of each of the techniques. 5.1 Dataset In our experiment we have used MNIST Handwritten digits dataset, a subset of a larger set NIST.[6] It consists of a database of 70,000 handwritten digits, divided into 60,000 model train- ing images and 10,000 images for the evaluation of the model. It contains images of digits taken from a variety of scanned documents, normalized in size and centered. This makes it an excellent dataset for evaluating models, allowing the developer to focus on the machine learning with very little data cleaning or preparation required. Each image is a 28 by 28 pixel square (784 pixels total) in order to get better accuracy and distinction between black and white pixels in the image. The dataset can be easily accessed from the link given below: http://yann.lecun.com/exdb/mnist/ FIGURE 5.1: Sample images of MNIST Dataset 5.2 Machine Learning Techniques:- • KNN • RFC • SVM 8
  • 16. List of Tables 9 5.3 Support Vector Machine A machine learning algorithm,[5] support vector machine algorithm is to seek out a hyperplane in an N-dimensional space (N — the amount of features) that distinctly classifies the info points. It’s basically to separate the 2 classes of knowledge points, there are many possible hyperplanes that would be chosen. Our objective is to seek out a plane that has the utmost margin that is the distance between data points of both classes. Maximizing the margin distance provides some reinforcement in order that future data points are often classified with more confidence. FIGURE 5.2: SVM Hyperplanes and Support Vectors To classify the info points we use decision boundaries that are called hyperplanes. Data points falling on either side of the hyperplane are often attributed to different classes. They will [5] be classified as positive and negative regions on the edges of hyperplane. Also, the dimension of the hyperplane depends upon the amount of features. Once we have the amount of inputs equals to 2, the hyperplane is simply a line and just in case of three input features it becomes a plane in two dimension but it becomes difficult to predict the hyperplane when number of features increases. FIGURE 5.3: Hyperplanes SVM
  • 17. List of Tables 10 The points which are closer to the hyperplanes are referred to as Support vectors which in- fluence the position and orientation of the hyperplane. Support vectors as you’ll see in picture are deciding the margin. When the position of support vectors changes, the margin also changes. Large Margin Intuition In logistic regression, we take the output of the linear function and squash the worth within the range of [0, 1] using the sigmoid function. If the squashed value is bigger than a threshold value (0.5) we assign it a label 1, else we assign it a label 0. In SVM, we take the output of the linear function and if that output is bigger than 1, we identify it with one class and if the output is -1, we identify is with another class. Since the edge values are changed to 1 and -1 in SVM, we obtain this reinforcement range of values ([-1, 1]) which acts as margin. Support Vector Machine (SVM) parameters in code FIGURE 5.4: SVM Parameter Code Steps to follow: • Import Library • Train data • Test data • Various options related to SVM training; like changing kernel, gamma and C value. • Create the model • model¡-svm(Target Predictor1+Predictor2+Predictor3, data=Train, kernel=’linear/polynomial’,gamma=0.1,cost=100) • Predict Output Tuning of SVM Parameters • The kernel parameter can be one from “Linear”,”Poly”,”rbf” etc. • Gamma value can be tuned by setting the “Gamma” parameter. • C value in Python is tuned by the “Cost” parameter in R.
  • 18. List of Tables 11 Pros and Cons associated with SVM • Pros: • Effective when number of dimension is greater than number of samples. • Effective in high dimensional spaces. • Efficient with a clear margin of separation. • Memory efficient because of using support vectors. • Cons: • Its performance gets effected due to noise data when target classes are overlapping. • Probability estimations are calculated by expensive five fold cross validation in it. • Performance gets effected due to large data set which demands more time in training. Conclusion: Support Vector Machine is an elegant and powerful supervised machine learning algorithm. 5.4 Random forest Another machine learning algorithm is Random [5] forests or random decision forests which are an ensemble learning method for classification, regression and other tasks that operate by constructing a multitude of decision trees at training time and outputting the class that is the mode of the classes or mean/average prediction of the individual trees. To make better model: 1. It should be having Features with predictive power. 2. No (low)-correlation between the trees of the forest. 3. A model has a big impact of the features we select and the hyper-parameters we choose. Random Forest Hyperparameters: • max-depth • min-sample-split • max-leaf-nodes • min-samples-leaf
  • 19. List of Tables 12 • n-estimators • max-sample (bootstrap sample) • max-features FIGURE 5.5: RFC Parameter Code Random Forest Hyperparameters in this code: N-Estimators: N-estimators determines the number of trees in forests.In this graph, we can clearly see that the performance of the model sharply increases and then stagnates at a certain level: FIGURE 5.6: N-Estimators Trend shows that with a large number of estimators in a random forest model the results are not best. Although it will not degrade the model, it can save you the computational complexity and prevent the use of a fire extinguisher on your CPU! N-jobs: This parameter is used to specify how many concurrent [5] processes or threads should be used for routines that are parallelized with joblib. N-jobs is an integer, specifying the maximum num- ber of concurrently running workers. If 1 is given, no joblib parallelism is used at all, which is useful for debugging. If set to -1, all CPUs are used. For n-jobs below -1, (n-cpus + 1 + n-jobs)
  • 20. List of Tables 13 are used. N-jobs is none by default, which means unset; it will generally be interpreted as n-jobs=1, unless the current joblib. Parallel backend context specifies otherwise. Conclusion: The random forest is a classification algorithm consisting of many decisions trees. It uses bag- ging and feature randomness when building each individual tree to try to create an uncorrelated forest of trees whose prediction is more accurate than that of any individual tree. 5.5 KNN Algorithm K nearest neighbors is also a machine learning algorithm that stores all available cases and clas- sifies new cases by a majority vote of its k neighbors. This algorithms segregates unlabeled data points into well-defined groups. How to select appropriate k value? Determining the value of k plays a significant role in determining the efficacy of the model. Thus, selection of k will determine how well the data can be utilized to generalize the results of the kNN algorithm. A large k value has benefits which include reducing the variance due to the noisy data; the side effect being developing a bias due to which the learner tends to ignore the smaller patterns which may have useful insights. KNN Algorithm- Pros and Cons • Pros: • Highly unbiased and simple algorithm in nature. • No prior assumption of the underlying data. • It is easy to implement and has gained good popularity. • Cons: • If we take a deeper look, this doesn’t create a model since there’s no abstraction process involved. • The prediction time is pretty high in this algorithm, and a lazy learner it is. • Building this algorithm requires time to be invested in data preparation. Steps to Follow: • Data collection
  • 21. List of Tables 14 • Preparing and exploring the data • Normalizing numeric data • Creating training and test data set • Training a model on data • Evaluate the model performance • Improve the performance of the model
  • 22. Chapter 6 Implementation of the Learning Techniques The paper is implemented by following the following steps:- 6.1 Procedure 1. Write the code for KNN, RFC and SVM. (The screenshots of the code is given in the section below) 2. Open command prompt(Write cmd in search bar). 3. Provide the directory to the folder where the code is written, by writing (cd Folder) in command prompt. 4. Install all the following requirements in your command prompt. 5. Requirements:- • Python 3.5 + (pip install python==3.5) • Scikit-Learn (pip install scikit-learn) • Numpy (pip install numpy) • Matplotlib (pip install matplotlib) 6. Now, run the python files on which you have written the code (python knn.py), (python svm.py) or (python rfc.py). After Running the python files, you will receive all the print statements in the ”summary.log” file. 6.2 Codes for Machine Learning Algorithm The following are the codes for the implementation of the machine learning algorithms (as discussed in the paper). 15
  • 23. List of Tables 16 6.2.1 Code for KNN Algorithm
  • 25. List of Tables 18 6.2.2 Code for SVM
  • 27. List of Tables 20 6.2.3 Code for Random Forest Classifier
  • 30. Chapter 7 Results & Observation While implementing the algorithm model on the training data, the results are observed on the test data, special focus on the accuracy of the model. With the calculated accuracy and precision, we can comprehend the efficiency of the training model. 7.1 Evaluation Metric In this paper, we have evaluated the machine learning techniques (as mentioned in the method- ology), upon the below given criteria: • Accuracy • Precision • Recall • F1-Score 7.2 Output of KNN Classification The image below shows a step-by-step output of the KNN Classifier. We have obtained an accuracy of 97.43% on the trained classifier,and on the prediction labels dataset, we got an accuracy of 96.72%. 23
  • 31. List of Tables 24 FIGURE 7.1: KNN-Confusion Matrix
  • 32. List of Tables 25 FIGURE 7.2: Validation Data Confusion Matrix for KNN FIGURE 7.3: Test Images for KNN Algorithm
  • 33. List of Tables 26 7.3 Output of SVM Classification The following image shows a step-by-step output of the SVM classifier. We have obtained an accuracy of 97.79% on trained classifier and 97.84% on prediction labels dataset.
  • 34. List of Tables 27 FIGURE 7.4: SVM-Confusion Matrix FIGURE 7.5: Validation Data Confusion Matrix for SVM
  • 35. List of Tables 28 FIGURE 7.6: Test Data Confusion Matrix for SVM FIGURE 7.7: Test Images for SVM Algorithm
  • 36. List of Tables 29 7.4 Output of Random Forest Classification The following image shows a step-by-step output of the RFC classifier. We obtained an accuracy of 96.78% on trained classifier and 96.91% on prediction labels dataset. newline FIGURE 7.8: RFC-Confusion Matrix
  • 37. List of Tables 30 FIGURE 7.9: Validation Data Confusion Matrix for RFC FIGURE 7.10: Test Data Confusion Matrix for RFC
  • 38. List of Tables 31 FIGURE 7.11: Test Images for RFC Algorithm 7.5 Confusion matrix In all the outputs of the classifiers, we see a confusion matrix. A confusion matrix defines a specific table that allows the visualization of the performance of an algorithm by providing the accuracy corresponding to each of the input and output classes.[2]
  • 39. List of Tables 32 FIGURE 7.12: KNN-Evaluation Metric for Test Images FIGURE 7.13: SVM-Evaluation Metric for Test Images
  • 40. List of Tables 33 FIGURE 7.14: RFC-Evaluation Metric for Test Images Accuracy RFC KNN SVM Trained Classifier 96.78% 97.43% 97.79% Test Images 96.91% 96.72% 97.84% TABLE 7.1: Accuracy Comparison 7.6 Machine Learning Accuracy & Test Error Comparison We have seen the working of three of the most commonly used Machine Learning algorithms used for Handwritten Digit recognition. The method of Random Forest Classifier is able to recognize the digits 96.91% correctly. Using the K Nearest Neighbors, we are able to get an ac- curacy of 96.72% for the digit recognition. Similarly, for the SVM classifier, we get an accuracy of 97.84% for the digit recognition.
  • 41. List of Tables 34 Model Test Error Rate KNN Classifier 3.28% Random Forest Classifier 3.09% Support Vector Machine 2.16% TABLE 7.2: Test Error Comparison 7.7 Result and Analysis Hence, we can conclude, after implementing the algorithm on the training data and test data; compared to all of the algorithms, SVM succeeded in achieving better accuracy (after that is RFC and lastly, KNN). The main reason for the better performance of the SVM than any other algorithms, is that SVM is developed to overcome the classification problems now recent stud- ies are made on the use of SVM to overcome the regression issues as well. Moreover, while implementing the following algorithms KNN algorithm took the longest time in predicting the test instances. Hence Support Vector Machine (SVM) clearly leaves K-NN behind in terms of efficiency in Prediction Time and also in terms of computation and memory load. 7.8 Conclusion An implementation of Handwritten Digit Recognition has been implemented in this paper.Additionally, some of the most widely used Machine Learning algorithms i.e. RFC, KNN and SVM have been trained and tested on the same data to draw a comparison between the simple Machine Learn- ing Techniques. Using the algorithms, an accuracy of 97.84% using SVM, 96.72% using KNN, 96.91% using RFC, was achieved. Also, the current implementation is done only using the CPU. For additional accuracy, reduced training and testing time, the use of GPU is required. Using GPU we will achieve parallel computing and attain much better results.
  • 42. References [1] Akkireddy Challa. ” automatic handwritten digit recognition on document images using machine learning methods”,jan 2019,blekinge institute of technology, karlskrona, sweden. Accessed Jan 03, 2021. [2] CM. ” confusion matrix”. Accessed Jan 03, 2021. [3] Anuj Dutt and Aash Dutt. ” handwritten digit recognition using deep learning”, volume-6, issue-7, july 2017, issn: 2278 – 1323. Accessed Jan 03, 2021. [4] Angona Sarker Masud Rana Abdullah Al Jobair S M Shamim, Mohammad Badrul Alam Miah. ”handwritten digit recognition using machine learning algorithms”,global journal of computer science and technology: Dneural artificial intelligence, vol-18,issue- 1,2018,. Accessed Jan 03, 2021. [5] Mayank Semwal Vipul Malhotra. ” detect malicious benign websites using machine learn- ing”. Accessed Jan 03, 2021. [6] Christopher J.C. Burges Yann LeCun, Corinna Cortes. ” the mnist database of handwritten digits”. Accessed Jan 03, 2021. 35