Skip to content

Benjamin-Onu/Digit-Classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

MNIST Digit Classification (Digits 1, 2, 3)

A neural network implementation from scratch using NumPy to classify handwritten digits (1, 2, and 3) from the MNIST dataset.

Table of Contents

Project Overview

This project implements a simple neural network from scratch (using NumPy) to classify handwritten digits (1, 2, and 3) from the MNIST dataset. The implementation includes:

  • Data loading and preprocessing
  • One-hot encoding of labels
  • Neural network with single layer
  • Softmax activation and cross-entropy loss
  • Training with gradient descent
  • Performance evaluation

Repository Structure

mnist-digit-classification/
├── mnist_neural_network.py # Main implementation script
├── README.md # This documentation file
├── requirements.txt # Python dependencies
├── images/ # Directory for output plots
│ ├── accuracy_vs_epochs.png
│ ├── accuracy_vs_lr.png
│ └── loss_vs_epochs.png
└── data/ # MNIST dataset (auto-downloaded)

Dependencies

  • Python 3.6+
  • NumPy
  • Matplotlib
  • Keras (for dataset loading)

Install requirements:

pip install -r requirements.txt

Implementation Details

Key components of the implementation:

  1. Data Preparation
  • Load MNIST dataset using Keras
  • Filter for only digits 1, 2, and 3
  • Flatten and normalize images (28x28 → 784-dim vectors)
  • One-hot encode labels
  1. Neural Network
  • Single layer architecture (784 input → 3 output)
  • ReLU activation function
  • Softmax output layer
  • Cross-entropy loss function
  1. Training
  • Batch gradient descent
  • Learning rate comparison (0.1 to 0.5)
  • 50 training epochs
  1. Evaluation
  • Test accuracy calculation
  • Loss and accuracy tracking
  • Prediction visualization

Results

The model achieves the following performance:

Metric Value
Training Accuracy ~98%
Test Accuracy ~96%
Training Time <1 minute

Learning rate comparison results:

Learning Rate Final Accuracy
0.1 94.2%
0.2 95.7%
0.3 96.1%
0.4 95.9%
0.5 95.3%

Credits

  • MNIST dataset from Yann LeCun and Corinna Cortes
  • NumPy for numerical computations
  • Keras for dataset loading utilities

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages