This project is a raw implementation of a Feed-Forward Neural Network to classify handwritten digits from the MNIST dataset.
Unlike standard implementations that rely on high-level frameworks like TensorFlow or PyTorch, this project builds the neural network entirely from scratch using only NumPy and Pandas. The goal was to deconstruct the "black box" of Deep Learning and understand the linear algebra and calculus governing forward propagation and gradient descent.
- Zero ML Frameworks: Logic is implemented using raw matrix multiplication and calculus.
- Custom Backpropagation: Manual implementation of the Chain Rule to calculate gradients.
- Vectorized Operations: Uses NumPy broadcasting for efficient computation over batches.
- Visual Validation: Includes a prediction visualizer to test the model against specific images.
The network consists of a 2-layer architecture (Input
-
Input Layer:
$784$ units (corresponding to$28 \times 28$ pixel images). -
Hidden Layer:
$10$ neurons with ReLU activation. -
Output Layer:
$10$ neurons with Softmax activation (representing probabilities for digits 0-9).
The core logic relies on the following signal flow designed from first principles:
The model learns by minimizing the loss via Gradient Descent, calculating derivatives recursively:
(Where m is the number of training examples)
├── train.csv # MNIST Training data (pixel values and labels)
├── main.py # Complete source code (Init, Prop, Descent)
└── README.md # Project documentation🛠️ Requirements
-
Python 3.x
-
NumPy
-
Pandas
-
Matplotlib (for visualizing predictions)
To install dependencies:
pip install numpy pandas matplotlib📊 Results
After training for 500 iterations with a learning rate (α) of 0.1:
-
Final Accuracy: ~85%
-
The model successfully converges and is able to predict handwritten digits with high confidence.
🧠 Learning Outcomes
Building this project helped solidify concepts in:
-
Linear Algebra: Matrix dimensionality and dot products in Neural Networks.
-
Calculus: Practical application of the Chain Rule for backpropagation.
-
Optimization: Understanding how Gradient Descent minimizes the Loss function.