Skip to content

macgreen23/AI_Project_1

Repository files navigation

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 torch

How 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.py helpers 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.long when using CrossEntropyLoss.
  • tqdm is only needed to run k_nearest_neighbors.py as it helps determine the length of time to finish processing.
  • Code is only tested using python 3.13.7

About

Code and dataset for Project 1 for CSC 4444.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published