This project is a small neural network built from scratch with NumPy to classify handwritten digits from the Kaggle Digit Recognizer dataset.
Install the dependencies:
pip install -r requirements.txtPlace the Kaggle train.csv in one of the locations the script already checks, for example:
models/data/train.csvYou can also pass a custom path when running the script:
python models/neural_network.py --data path/to/train.csvTrain the model and generate example prediction images:
python models/neural_network.pyThe script will save sample predictions to outputs/.
I ran the model on models/data/train.csv with the default settings in the script and got the following training accuracy progression:
| Iteration | Accuracy |
|---|---|
| 0 | 0.1148 |
| 500 | 0.8503 |
| 1000 | 0.8830 |
| 1500 | 0.8974 |
| 2000 | 0.9054 |
| 2500 | 0.9109 |
| 3000 | 0.9151 |
| 3500 | 0.9184 |
| 4000 | 0.9210 |
| 4500 | 0.9236 |
| 4950 | 0.9253 |
Example predictions from the final run:
- Index 30: predicted 7, label 7
- Index 3: predicted 8, label 8
- Index 50: predicted 8, label 8
- Index 8: predicted 0, label 0
Generated images:
outputs/prediction_30.pngoutputs/prediction_3.pngoutputs/prediction_50.pngoutputs/prediction_8.png
- The script uses a simple 2-layer neural network with ReLU and softmax.
- The training accuracy above is on the training split used by the script, not a separate Kaggle leaderboard score.
- If you want to run fewer iterations for a quick test, use
--iterations.
Download the data from Kaggle: