This project builds an Artificial Neural Network (ANN) using TensorFlow/Keras to classify handwritten digits from the MNIST dataset. An ANN is the simplest form of deep learning — layers of interconnected neurons that learn patterns from data.
The MNIST dataset contains 70,000 grayscale images of handwritten digits (0-9):
- Training set: 60,000 images
- Test set: 10,000 images
- Each image is 28x28 pixels (784 features when flattened)
- 10 classes: digits 0 through 9
To build a simple feedforward neural network that learns to recognize handwritten digits from pixel values alone, demonstrating the core concepts of deep learning — layers, activation functions, and backpropagation.
- ANNs are the foundation of deep learning — understanding them is essential before CNNs or RNNs
- A simple 2-3 layer network can achieve >97% accuracy on MNIST
- ANN introduces key concepts: forward propagation, loss functions, optimization, and epochs
- Starting simple makes the jump to CNNs more understandable
- Python
- Jupyter Notebook
pandas,numpyfor data handlingmatplotlib,seabornfor visualizationtensorflow/kerasfor building and training the neural network
- Input Layer: 784 neurons (28x28 flattened)
- Hidden Layer 1: 128 neurons, ReLU activation
- Dropout: 20% for regularization
- Hidden Layer 2: 64 neurons, ReLU activation
- Output Layer: 10 neurons, Softmax activation
Total parameters: ~110,000
-
Data Loading & Exploration:
- Loaded MNIST from
tf.keras.datasets - Visualized sample digits
- Checked class distribution
- Loaded MNIST from
-
Data Preprocessing:
- Normalized pixel values to [0, 1] range
- One-hot encoded labels for multi-class classification
- Flattened 28x28 images to 784-length vectors
-
Modeling:
- Built a Sequential model with Dense layers
- Used categorical crossentropy loss and Adam optimizer
- Trained for 10 epochs with validation split
-
Evaluation & Visualization:
- Evaluated on test set
- Plotted training/validation accuracy and loss curves
- Visualized sample predictions
- The ANN achieved >97% accuracy on test data after 10 epochs
- Training and validation accuracy converged smoothly — minimal overfitting
- Most misclassifications occurred between visually similar digits (4 vs 9, 3 vs 8)
- Dropout regularization helped prevent overfitting
ML-DL-Projects/
├── Deep-Learning/
│ └── ANN/
│ ├── dataset/ # (MNIST loaded via tf.keras, no CSV)
│ ├── images/
│ │ ├── training_history.png
│ │ └── sample_predictions.png
│ ├── notebooks/
│ │ └── ANN_Example.ipynb
│ └── README.md
├── uv.lock
├── pyproject.toml
To run this project locally:
cd ML-DL-Projects
uv syncjupyter notebookThen open ANN_Example.ipynb.
- Add more hidden layers or increase neurons and see how accuracy changes
- Experiment with different activation functions (tanh, leaky ReLU)
- Try different optimizers (SGD, RMSprop) and compare convergence
- Compare ANN performance directly with CNN on the same dataset
Feel free to reach out if you have questions or want to collaborate!