This project involves building a neural network from scratch to classify handwritten digits from the MNIST dataset. The implementation uses only the numpy and pandas libraries for data manipulation and mathematical operations, without relying on high-level frameworks like TensorFlow or PyTorch.
The MNIST dataset consists of 28x28 grayscale images of handwritten digits, with each image labeled from 0 to 9. The goal is to build a neural network that can correctly classify these digits.
Requirements Python 3.x Numpy Pandas Math (Python standard library) You can install the required libraries using pip install requirements.txt
The MNIST dataset can be downloaded from here. It includes a training set of 60,000 examples and a test set of 10,000 examples.
Data flows from layer to layer. retrieve output. y = network(x, w)
compare output of neural network with the desired output.
use gradient descent to change parameters to be better for future.
Repeat this process training the model.
- implement shaping properly
- think about a convolutional model instead of regular NN.
Begin by importing the necessary libraries
Load the MNIST dataset and preprocess it by normalizing the pixel values and converting labels to one-hot encoding:
Initialize the weights and biases for the neural network
Define the sigmoid, tanh and softmax activation functions and their derivatives:
Calculate the cross-entropy loss:
Implement backward propagation:
Update the parameters using gradient descent:
Train the neural network by iterating through multiple epochs:
Evaluate the trained model on the test set:
This project demonstrates how to build a simple neural network from scratch using basic Python libraries. By understanding and implementing each step manually, you gain deeper insights into the workings of neural networks.