Report
Report
1. Introduction
1.1 Objective
The primary goal of this assignment was to implement a simple neural network with up to five
layers to classify handwritten digits from the MNIST dataset. This involved designing the
architecture, implementing both forward and backward propagation, and optimizing weights. The
implementation was strictly done using Python and the NumPy library, without relying on pre-
built libraries like PyTorch or TensorFlow.
1.2 Dataset
The MNIST dataset consists of 60,000 training images and 10,000 testing images of handwritten
digits, each labeled as a number between 0 and 9. The images are grayscale with a resolution of
28 \times 28 pixels.
2. Methodology
2.1 Data Preparation
The dataset was processed to make it suitable for training:
• Images were normalized to values between 0 and 1 for consistency.
• Labels were extracted as integers ranging from 0 to 9.
• Mini-batches were created using the create_mini_batches function, which shuffled
the data to ensure unbiased training.
2.2 Model Architecture
The neural network architecture was implemented as follows:
1. Convolutional Layer:
• 3 \times 3 filters, with 16 feature maps.
• Extracts spatial features from the input images.
2. Flatten Layer:
• Converts the feature maps into a 1D vector.
3. Fully Connected Layers:
• FC1: 128 neurons, using the ReLU activation function.
• FC2: 10 neurons, using the Softmax activation function to output class
probabilities.
Activation Functions:
• ReLU: f ( x )=max(0 , x)
exp x i
Softmax ( xi ) =
∑ exp x j
j
where W represents the weights, \alpha is the learning rate, and \nabla L is the gradient of the
loss. The learning rate was set to 0.01 for this implementation.
3. Experimental Results
3.1 Experimental Setup
• Programming Environment: Python 3 and NumPy.
• Hardware: MacBook Air.
• Dataset: MNIST (60,000 training images, 10,000 testing images).
3.2 Results
The following tables present the loss values for each epoch and accuracy of tranning & test sets:
5. Conclusion
This project successfully implemented a neural network from scratch using Python and NumPy
to classify MNIST digits. The model achieved a training accuracy of 92.00% and a testing
accuracy of 92.05%. Future improvements could include the use of dropout and batch
normalization to enhance performance further.
6. References