Applications are contained in the MyFiles folder.
By Rheinard Zadanowsky, Edmond Wong, Lucas Depaola, Chaoji Yang, and Matthew Niemczyk.
This repository contains a Python-based Machine Learning project focused on implementing neural networks for classification tasks. The project includes binary classification, feedforward multi-class classification, and convolutional neural network classification.
The project uses the Iris dataset for binary and feedforward multi-class classification, and the MNIST dataset for CNN-based handwritten digit classification.
This project implements neural network models from scratch using Python and NumPy. The program trains and evaluates models using forward propagation, loss computation, backpropagation, gradient descent, activation functions, and data preprocessing.
The project includes three main classification modes:
- Binary classification using the Iris dataset
- Feedforward multi-class classification using the Iris dataset
- CNN multi-class classification using the MNIST dataset
The program also generates output text files and visual graphs showing loss curves and actual vs. predicted classification results.
- Python neural network implementation
- Binary classification
- Feedforward multi-class classification
- Convolutional neural network classification
- Iris dataset support
- MNIST dataset support
- Local MNIST dataset caching using
mnist_784.npz - OpenML MNIST dataset fetching if local file is unavailable
- Forward propagation
- Backpropagation
- Gradient descent
- Xavier initialization for feedforward neural networks
- He/Kaiming initialization for CNN layers
- Sigmoid activation
- ReLU activation
- Softmax activation
- Cross-entropy loss
- One-hot encoding
- Mini-batch training for CNN
- Max pooling
- Convolution operations
- Loss curve plotting
- Actual vs. predicted result plotting
- Output result files for model loss records
NeuralNetwork.py- main Python source code containing the neural network implementations, training logic, dataset loading, plotting, and program menumnist_784.npz- local cached MNIST dataset file used by the CNN model, if included in the repo/submission- Output text files are generated after running the models
- Output graph images are generated after running the models
IDE used:
IntelliJ IDEA 2025.1 (Ultimate Edition)
Build #IU-251.23774.435, built on April 14, 2025
Plugins used:
Python - version 251.23774.460
Python Community Edition - version 251.23774.460
Virtual environment:
.venv
Python interpreter:
Python 3.13
numpy - Version: 2.2.3
scikit-learn - Version: 1.6.1
matplotlib - Version: 3.10.1
import numpy as number_array
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.datasets import fetch_openml
import matplotlib.pyplot as plt
from numpy.lib.stride_tricks import sliding_window_view
import osnumpy- numerical computations and basic data processingload_iris- loads the Iris datasettrain_test_split- splits the dataset into training and testing datafetch_openml- fetches the MNIST dataset from OpenMLmatplotlib.pyplot- creates graphs and plotssliding_window_view- supports CNN convolution operationsos- checks for and saves the local MNIST dataset file
The Iris dataset is used for:
- Binary classification
- Feedforward multi-class classification
For binary classification, the program filters the Iris dataset to use two classes.
For multi-class classification, the program uses the full Iris dataset with all three classes.
The MNIST dataset is used for CNN multi-class classification.
Website for MNIST dataset:
https://www.openml.org/search?type=data&sort=runs&id=554&status=active
Please use the local mnist_784.npz file in the compressed submission for the source code for the Neural Network. Make sure both files are in the same directory so the Neural Network Python file can use and pick up the MNIST dataset.
If this does not work, please make sure to have an internet connection so the source code can fetch and retrieve the MNIST dataset from the OpenML website.
When the program runs, the user chooses between binary classification and multi-class classification.
For binary classification, the program trains a feedforward neural network on a filtered version of the Iris dataset. It uses forward propagation, sigmoid output activation, loss calculation, backpropagation, and gradient descent.
For feedforward multi-class classification, the program trains a neural network on the full Iris dataset. It uses one-hot encoding, softmax output activation, cross-entropy loss, and gradient descent.
For CNN multi-class classification, the program trains a convolutional neural network on the MNIST dataset. The CNN includes convolutional layers, ReLU activation, max pooling, a dense layer, an output layer, and softmax classification.
After training, the program prints loss values, computes experimental loss on test data, calculates accuracy, saves output text files, and creates plots for training loss and actual vs. predicted results.
-
Open the project in IntelliJ IDEA or another Python-compatible IDE.
-
Make sure the virtual environment is active.
-
Make sure the required Python libraries are installed:
pip install numpy scikit-learn matplotlib-
Place
mnist_784.npzin the same directory asNeuralNetwork.pyif using the local MNIST dataset file. -
Run:
python NeuralNetwork.py- Follow the prompts in the terminal.
The program first asks:
For Binary Classification enter 'b' or for Multi-class Classification enter 'm':
If multi-class classification is selected, it then asks:
For CNN enter 'c' or Feedforward enter 'f':
When running the program, please follow the suggested parameters so the expected results are presented.
learning_rate = 0.4
hidden_layer_size = 4
upper_boundary = 0.0001
num_iterations = 200
learning_rate = 0.33
number_iterations = 30
batch_size = 64
upper_boundary = 0.000001
learning_rate = 0.01
hidden_layer_size = 4
upper_boundary = 0.000001
num_iterations = 5000
The program generates text output files containing loss records and experimental loss values.
Possible generated output files include:
Output_FF_Binary_Classification.txt
Output_CNN_Multi_Class_Classification.txt
Output_FF_Multi_Class_Classification.txt
The program also generates graph images showing loss curves and actual vs. predicted values.
Possible generated graph files include:
[Iris Dataset - Binary] Loss.png
[Iris Dataset - Binary] Actual vs. Predicted values.png
[Iris Dataset - Multi-class] Loss.png
[Iris Dataset - Multi-class] Actual vs. Predicted values.png
[MNIST - Multi-class] Loss.png
[MNIST - Multi-class] Actual vs. Predicted values.png
- Python
- NumPy
- scikit-learn
- matplotlib
- OpenML
- Neural networks
- Feedforward neural networks
- Convolutional neural networks
- Backpropagation
- Gradient descent
- Softmax classification
- Binary classification
- Multi-class classification
- Data visualization
This project was created for the ICSI436 Machine Learning course to practice building and training neural networks.
The project demonstrates how neural networks can be implemented using lower-level numerical operations instead of relying on high-level deep learning frameworks. It also shows how different neural network models can be applied to binary classification, multi-class classification, and image classification tasks.