Pure Math Neural Network — 2-Layer MNIST MLP Classifier with Mini Batches, Momentum, L2 Regularization, and Evaluation Tools
This project started as a minimal two-layer neural network built from scratch in Python using only NumPy. Ultimately, I ended up improving on it with more advanced techniques (see features). As I improved on the model, I would stumble upon even better improvments and push myself to implement them without using any ML libraries such as PyTorch or TensorFlow. Feel free to fork and experiment, I found this to be a great project for ML fundementals.
784inputs ->128HL neurons ->10outputs- Fully "manual"
forward and backward propagation Mini-batch gradient descentwithmomentumL2 regularization- Matplotlib
accuracy/loss visualizationandconfusion matrix ReLUandsoftmaxactivations- Explicit
Cross Entropy Lossfunction
git clone https://github.com/SawyerAlston/MNIST-NN-Pure-Math.git
cd MNIST-NN-Pure-MathThis project only uses Numpy (for complex math), Matplotlib (for plotting), and pandas (for data handling).
pip install -r requirements.txtYou can change the following hyperparameters in config.py.
learning_rate = 0.01
epochs = 50
lambda_reg = 0.001
beta_mom = 0.85Running
main.pywill train, test, and evaluate results.
python main.pyModel will reach
~98%accuracy and~0.08loss after50epochs.
Iteration #: 0 | Accuracy: 0.8773827956989247 | Loss: 0.4424950074026731
Iteration #: 5 | Accuracy: 0.9697483870967742 | Loss: 0.10922517157056087
Iteration #: 10 | Accuracy: 0.9786 | Loss: 0.0831458624003045
Iteration #: 15 | Accuracy: 0.981666129032258 | Loss: 0.07446231924020297
Iteration #: 20 | Accuracy: 0.9835666666666667 | Loss: 0.07054676251877758
Iteration #: 25 | Accuracy: 0.9839489247311828 | Loss: 0.06814719627101269
Iteration #: 30 | Accuracy: 0.9845833333333334 | Loss: 0.06678000449212522
Iteration #: 35 | Accuracy: 0.9852833333333333 | Loss: 0.06518376537020491
Iteration #: 40 | Accuracy: 0.9852166666666666 | Loss: 0.06465588259409603
Iteration #: 45 | Accuracy: 0.9851166666666666 | Loss: 0.064073599008369
FINAL TEST RESULTS | Accuracy: 0.9788978897889788 | Loss: 0.07987769345952195config.py: configuration file for modeldata.py: downloads and sets up MNIST CSV datamain.py: runs the model (train and test)model.py: core functions (init, forwardprop, backprop, etc.) of the modeltrain_test.py: functions to train and test the modelrequirements.txt: required librariesPerformance Plots/: plots of model performance
This project is licensed under the MIT License.


