Classifying Hand-Written Digits Using Neural Network
Classifying Hand-Written Digits Using Neural Network
Neural Network
Model
Creating the
Model
• MNIST is a simple computer vision dataset which consists of different
images labels for each handwritten digit conveying that which digit is.
The data from MNIST dataset which consists of different styled (28 x
28) pixel images. So, our input layer contains 784 input neurons. The
training and test set are different, is necessary for the purpose of
helping the neural network learn from the training dataset only.
Rather than memorizing the entire dataset and then reciprocating the
same, it actually predicts the test set.
• We also the changed the shape of the labels by one hot encoding. It is
a process by which categorical variables are converted into a form
that could be provided to ML algorithms to do a better job in
prediction.
• Before using the images which are in 28*28 pixels, we need to change the
shape of that so that it can be easily fed to the model. For the changing the
shape of the image data which is two dimensional array, we will use numpy’s
reshape function and the new shape for the images will be a single
dimensional array of 784.
• Pixel values, in this dataset, range from 0 to 255. These default values cane be
used if we only want to display our images but for the neural network to learn
the weights and biases for different layers, computations will be more
effective and fast if we normalized these values. In order to normalize the
data, we can calculate the mean and standard deviation for each example.
• We will then normalise both the training and test set using the mean and
standard deviation. One important that we will need to apply the same mean
and standard deviation calculated from training set to the test set.
• Now, the data has been processed, we can start with the model. For creating
the model, we are going to use the sequential class of the Keras package. We
will have to specify the number of the layers, how many nodes, layers will be
dense or not, type of activation use, etc.
• After the declaring the model’s structure we can compile it using the compile
function. Parameters such as loss, optimizing algorithm which is to be used
are specified here. We can also set which metrics we want to see. One metric
commonly used is “accuracy”.
• Now, we can train the model use the fit function. It takes the training dataset,
training labels and numbers of epochs as it’s parameter. Epoch is like an
iteration of all the examples going through the model.
• In order to ensure that this is not a simple memorization of the training
dataset by the machine, we will evaluate the performance of the model on
the test set. We simply use the evaluate method on the model. This function
will return the accuracy and the loss value.
• We will then plot the few test set images along with their predicted and
actual labels and see how our trained model actually performed.
• We will also look at the probability scores for some individual digit sample
that the model predicted wrong class.
b b b
X1 w w w
n1 n1 n1
w
...........
...........
...........
...........
w y
w w
w
X784 w n128 w
w n128 n10
•Shifeng Huang [4] : “Influence of Different Convolutional Neural Network Settings on the
Performance of MNIST Handwritten Digits Recognition”. The project use convolutional
neural network to classify hand-written digits. It uses Tensorflow as backend and
parameters such as iterations, hidden layers were tuned to check how it affects accuracy.
•The model was trained and evaluated against an unknown dataset. It showed greater
accuracy even if the number of layers, epochs were low. We can achieve greater
accuracy but it can lead to overfitting of the model. Overfitting negatively affect the
model as it means the model will memorize the noise of the data and it will not
recognize unknown data properly.
•As MNIST dataset is used in other Machine Learning and Deep learning problems such
as Object Detection, Image Classification. We can apply the knowledge gained by tackling
the Digit Classification problem to other ML, DL problem.
•The accuracy can be manipulated i.e increased or decreased by parameter tuning.
Parameter tuning includes choosing number of layers, which activation function to use,
number of epochs, which optimizer to use, etc.