Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 99 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,128 @@
# Handwritten Digit Recognition from Scratch
# Digit Recognition using Neural Network (From Scratch)

A neural network built from **scratch using pure Python** to recognize MNIST handwritten digits with **95-97% accuracy** — no NumPy, TensorFlow, or PyTorch!
A Python implementation of a handwritten digit recognition system built entirely from scratch. This project focuses on understanding the mathematical foundations of neural networks without relying on high-level deep learning frameworks.

## 🎯 Features
The goal is educational clarity, architectural transparency, and strong fundamentals in machine learning implementation.

- ✅ Pure Python implementation (no ML libraries)
- ✅ Custom matrix operations from scratch
- ✅ Forward & backward propagation
- ✅ Mini-batch gradient descent
- ✅ 95-97% test accuracy on MNIST
---

## Project Overview

This repository implements a fully connected neural network to classify handwritten digits from the MNIST dataset. All core components such as forward propagation, backpropagation, weight updates, and data handling are manually implemented.

This project demonstrates:

* Manual neural network implementation
* Matrix-based forward and backward propagation
* Gradient descent optimization
* Dataset handling and preprocessing
* Modular and readable Python structure

---

## Project Structure

## 🏗️ Architecture
```
Input (784) → Hidden (128, ReLU) → Output (10, Softmax)
digitrecognition/
├── data_loader.py # Loads and preprocesses dataset
├── download_mnist.py # Downloads MNIST dataset
├── find_data.py # Utility to locate dataset files
├── my_math.py # Custom mathematical helper functions
├── neural_network_scratch.py # Core neural network implementation
├── show_structure.py # Displays model architecture details
├── train.py # Training script
├── test_single.py # Test prediction for a single sample
├── README.md
└── .gitignore
```

## 🚀 Quick Start
---

## Technologies Used

* **Language:** Python
* **Numerical Computation:** NumPy
* **Dataset:** MNIST

No high-level ML frameworks such as TensorFlow or PyTorch are used. All learning logic is implemented manually.

---

## How It Works

1. MNIST dataset is downloaded and prepared.
2. Data is normalized and structured for training.
3. A feedforward neural network performs prediction.
4. Backpropagation computes gradients.
5. Weights are updated using gradient descent.

---

## Setup Instructions

### 1. Clone the Repository

```bash
# Clone repository
git clone https://github.com/kaushalrog/digitrecognition.git
cd digitrecognition
```

### 2. Install Dependencies

```bash
pip install numpy
```

# Install matplotlib (only dependency)
pip install matplotlib
### 3. Download Dataset

# Download MNIST data
```bash
python download_mnist.py
```

### 4. Train the Model

# Train model
```bash
python train.py
```

## 📊 Results
### 5. Test a Single Sample

- **Training Accuracy**: ~96-98%
- **Test Accuracy**: ~95-97%
- **Training Time**: ~5-10 minutes (20 epochs)
```bash
python test_single.py
```

## 📁 Files
---

- `my_math.py` - Custom matrix operations
- `data_loader.py` - MNIST loader
- `neural_network_scratch.py` - Neural network
- `train.py` - Training script
## Learning Objectives

## 🧠 What's Inside
This project is ideal for understanding:

Built from scratch:
- Matrix class with all operations
- ReLU & Softmax activations
- Cross-entropy loss
- Backpropagation algorithm
- He weight initialization
- Mini-batch gradient descent
* Neural network internals
* Backpropagation mathematics
* Gradient descent optimization
* Matrix operations in ML
* Building ML systems without frameworks

## 👨‍💻 Author
---

**Kaushal** - [GitHub](https://github.com/kaushalrog)
## Future Improvements

## 📝 License
* Add configurable hyperparameters
* Implement mini-batch gradient descent
* Add performance metrics visualization
* Export trained model weights
* Build a simple web interface for predictions

MIT License
---

## License

This project is licensed under the MIT License.

---

⭐ Star if you found this helpful!
## Author

Kaushal S
GitHub: h