This project builds an Artificial Neural Network (ANN) that classifies handwritten digits, 0 through 9, using the classic MNIST dataset. The full workflow lives inside a single Colab notebook and covers everything from raw pixel data to a trained model with 97.43% test accuracy.
It is a clean example of how a relatively simple feed forward network, with the right preprocessing and a touch of dropout regularization, can perform extremely well on a well structured image classification problem.
| 🎯 What | 📋 Detail |
|---|---|
| Final Test Accuracy | 97.43% |
| Dataset Size | 42,000 labeled digit images |
| Input Features | 784 pixels per image (28 x 28 flattened) |
| Architecture | 4 layer fully connected ANN with dropout |
| Training Epochs | 10 |
| Framework | TensorFlow / Keras Sequential API |
flowchart LR
A[📂 Load mnist.csv] --> B[🔍 Explore data]
B --> C[⚙️ Normalize pixels 0 to 1]
C --> D[🏷️ One hot encode labels]
D --> E[✂️ Train test split]
E --> F[🏗️ Build ANN model]
F --> G[🚀 Train for 10 epochs]
G --> H[📊 Evaluate accuracy]
H --> I[🖼️ Visualize predictions]
The dataset is the classic MNIST handwritten digits dataset, provided here as a flat CSV file (mnist.csv) rather than the usual image format.
- 🧾 42,000 rows, each representing one digit image
- 🎨 785 columns total, one
labelcolumn plus 784pixel0topixel783columns - 🔢 Each pixel value ranges from 0 to 255, representing grayscale intensity
- 🧩 Every row, once reshaped, forms a 28 x 28 grayscale image
Before training, the pixel values are scaled down to a 0 to 1 range, and the digit labels are converted into one hot encoded vectors for the 10 output classes.
A simple yet effective Sequential ANN built with Keras:
model = Sequential([
Dense(256, activation='relu', input_shape=(784,)),
Dropout(0.3),
Dense(128, activation='relu'),
Dropout(0.3),
Dense(64, activation='relu'),
Dense(10, activation='softmax')
])| Layer | Type | Units | Activation | Notes |
|---|---|---|---|---|
| 1 | Dense | 256 | ReLU | Input layer, takes 784 flattened pixels |
| 2 | Dropout | — | — | 30% dropout for regularization |
| 3 | Dense | 128 | ReLU | Hidden layer |
| 4 | Dropout | — | — | 30% dropout for regularization |
| 5 | Dense | 64 | ReLU | Hidden layer |
| 6 | Dense | 10 | Softmax | Output layer, one node per digit |
⚙️ Compilation settings
- 🧮 Optimizer:
Adam - 📉 Loss function:
categorical_crossentropy - 📈 Metric tracked:
accuracy
The model was trained for 10 epochs with a batch size of 64, using an 80/20 train test split.
| Epoch | Train Accuracy | Val Accuracy | Train Loss | Val Loss |
|---|---|---|---|---|
| 1 | 75.48% | 94.60% | 0.7642 | 0.1741 |
| 5 | 96.70% | 97.18% | 0.1029 | 0.0931 |
| 10 | 98.18% | 97.43% | 0.0591 | 0.0942 |
📊 Both accuracy and loss curves for training and validation are plotted at the end of training, making it easy to visually confirm the model is learning well without overfitting heavily.
After training, the model is evaluated on the untouched 20% test split. The notebook also picks the first 5 test images and displays each one alongside its true label and the model's predicted label, giving a quick visual sanity check on real predictions rather than just a single accuracy number.
| Category | Tools Used |
|---|---|
| 🐍 Language | Python 3 |
| 🧠 Deep Learning | TensorFlow, Keras |
| 📊 Data Handling | Pandas, NumPy |
| 📈 Visualization | Matplotlib |
| 🤖 Preprocessing | Scikit learn (train_test_split) |
| ☁️ Environment | Google Colab |
MNIST-by-using-ANN-model/
│
├── mnist (1).ipynb # Main notebook: data loading, training, evaluation
└── README.md # You are here
-
Clone the repository
git clone https://github.com/sarthakNaikare/MNIST-by-using-ANN-model.git
-
Open the notebook Upload
mnist (1).ipynbto Google Colab or run it locally in Jupyter. -
Get the dataset The notebook expects a file named
mnist.csvat/content/mnist.csv. Place your copy of the MNIST CSV dataset there before running. -
Run all cells Execute the notebook top to bottom. Training takes well under a minute per epoch on Colab's standard runtime.
- 🧬 Swap the ANN for a CNN to push accuracy even higher
- 🎛️ Add hyperparameter tuning (learning rate, layer sizes, dropout rate)
- 🛑 Introduce early stopping and learning rate scheduling
- 🧪 Build a small confusion matrix view to spot which digits get confused most often
- 🌐 Wrap the trained model in a simple web demo for live digit recognition