๐ง MNIST Digit Classification using TensorFlow & Keras
This project demonstrates handwritten digit classification on the MNIST dataset using TensorFlow and Keras. Multiple neural network architectures are implemented and compared to show how model depth and feature handling affect accuracy.
๐ Project Overview Dataset: MNIST (28ร28 grayscale images of digits 0โ9) Framework: TensorFlow / Keras Language: Python Evaluation: Accuracy & Confusion Matrix The project progressively improves the model: Simple logistic regression One hidden layer neural network Neural network with automatic flattening
๐๏ธ Dataset Details Training samples: 60,000 Test samples: 10,000 Image size: 28 ร 28 Labels: 0โ9 Each image is normalized by dividing pixel values by 255.
๐งช Model Experiments๐น Model 1: Logistic Regression (Baseline) Input Layer (784) โ Dense(10) with Sigmoid Input flattened manually Loss: sparse_categorical_crossentropy Optimizer: Adam Epochs: 5
๐ Observation: Struggles with visually similar digits like 5 vs 7 and 8 vs 9 ๐น Model 2: One Hidden Layer Neural Network Input (784) โ Dense(100) with ReLU โ Dense(10) with Sigmoid
Adds non-linearity Better feature extraction Epochs: 5
๐ Improvement: Higher accuracy Reduced misclassifications Cleaner confusion matrix ๐น Model 3: Flatten Layer + Hidden Layer (Best Model) Flatten(28ร28) โ Dense(100) with ReLU โ Dense(10) with Sigmoid
No manual reshaping needed Cleaner architecture Epochs: 10
๐ Best performance among all models
๐ Results & Visualizations Sample Predictions Correct classification of handwritten digits Visual examples include digits 5 and 7 Confusion Matrices Heatmaps created using Seaborn Shows class-wise prediction accuracy Clearly highlights improvements across models Confusion matrices demonstrate fewer off-diagonal errors as model complexity increases.
๐ ๏ธ Tech Stack Python TensorFlow / Keras NumPy Matplotlib Seaborn
๐ How to Run pip install tensorflow numpy matplotlib seaborn python mnist_classifier.py
๐ Key Learnings Importance of hidden layers for non-linear data Effect of feature flattening How confusion matrices help diagnose model weaknesses Progressive improvement through architectural changes
๐ Future Improvements Replace sigmoid with softmax in output layer Add Dropout for regularization Try CNNs for spatial feature learning Hyperparameter tuning