A complete implementation of a Neural Network built entirely from scratch using NumPy, implementing both forward propagation and backpropagation without using deep learning frameworks like TensorFlow or PyTorch.
This project demonstrates the core mathematical foundations behind neural networks, including dense layers, activation functions, loss functions, gradient computation, and parameter updates.
This project implements a fully functional neural network pipeline including:
- Forward propagation
- Backward propagation (gradient calculation)
- Softmax classification
- Categorical Cross-Entropy loss
- Accuracy evaluation
- Spiral dataset classification
The goal of this project is to understand how neural networks work internally by implementing every component manually.
The following components are implemented from scratch:
- Weight initialization
- Bias initialization
- Forward pass
- Backward pass (gradient calculation)
- ReLU (Rectified Linear Unit)
- Softmax
- Categorical Cross-Entropy
- Chain rule based gradient calculation
- Gradient propagation through layers
- Class prediction using
argmax - Classification accuracy evaluation
The project uses the Spiral Dataset, commonly used for testing neural networks on nonlinear classification problems.
Features:
- 2 input features
- 3 classes
- 300 samples
Neural Network Structure:
Input Layer (2 features)
│
▼
Dense Layer (2 → 3)
│
▼
ReLU Activation
│
▼
Dense Layer (3 → 3)
│
▼
Softmax Activation
│
▼
Categorical Cross Entropy Loss
Forward pass computes predictions through the network:
- Input data passes through Dense layer
- ReLU activation introduces non-linearity
- Second Dense layer computes class scores
- Softmax converts scores to probabilities
- Loss function evaluates prediction error
Backpropagation computes gradients to update weights:
- Loss gradient is calculated
- Softmax gradients propagate backward
- Gradients flow through Dense layers
- Weights and biases are updated using gradient descent
neural-network-from-scratch/
│
├── forwardpropagation.py
├── backpropagation.py
- Python
- NumPy
- Object Oriented Programming
No external machine learning libraries are used.
- Clone the repository
git clone https://github.com/yourusername/neural-network-from-scratch.git- Navigate to the project directory
cd neural-network-from-scratch- Run the script
python main.pyLoss: 1.09
Accuracy: 0.36
As training progresses:
Loss: 0.32
Accuracy: 0.92
This project helps understand:
- How neural networks perform matrix computations
- How activation functions work
- How gradients are calculated
- How backpropagation trains models
- The mathematics behind deep learning
- Implement Optimizers (SGD, Adam)
- Add Dropout Regularization
- Implement multiple hidden layers
- Add training loop with epochs
- Visualization of decision boundaries