Project: MNIST Classifiers
This repository implements several simple classifiers for MNIST provided as raw PNG images in the MNIST/ folder. Implementations include:
- K-Nearest Neighbors (NumPy)
- Bernoulli Naive Bayes (NumPy)
- Linear classifier (L2 loss) (PyTorch)
- Multilayer Perceptron (PyTorch)
- Convolutional Neural Network (PyTorch)
Quick environment setup
python -m pip install --upgrade pip
python -m pip install numpy pillow matplotlib scikit-learn tqdm torchHow to run
- RUN ALL:
bash run_all.sh
- MLP (PyTorch):
python multilayer_perception.py
- CNN (PyTorch):
python convolutional_network.py
- Linear classifier (PyTorch):
python linear_classifier.py
- Naive Bayes (NumPy):
python naive_bayes.py
- KNN (NumPy):
python k_nearest_neighbors.py
What the scripts do
- Each training script saves results under
results/<model>/<timestamp>/- Classification report (text)
- Confusion matrix (CSV)
- Optional visualizations (PNG)
Notes
- The repository uses
preprocessing.pyhelpers to load PNG images and return either NumPy arrays (collect_np_dataset) or PyTorch tensors (collect_torch_dataset). - Labels are integer class indices (0–9). PyTorch models expect targets as
torch.longwhen usingCrossEntropyLoss. tqdmis only needed to runk_nearest_neighbors.pyas it helps determine the length of time to finish processing.- Code is only tested using python 3.13.7