This repository contains the implementation of a Multilayer Perceptron (MLP) or Deep neural network from scratch, using only maths. It aims to predict whether a cancer is malignant or benign using the Wisconsin breast cancer dataset.
The Multilayer Perceptron (MLP) is a type of artificial neural network that consists of multiple layers of neurons, each layer fully connected to the next. This project is an implementation of an MLP from scratch without the use of high-level machine learning libraries. It features optimization algorithms such as Adam, Nesterov momentum, L2 regularization, Xavier and He weights initializer, batch, mini-batch and stochastic gradient descent.
The MLP is trained to classify whether a breast cancer tumor is malignant or benign based on features extracted from cell images.
The main objectives of this project are:
- Implement the core algorithms of an MLP including forward propagation, backward propagation, and gradient descent.
- Train the MLP on the Wisconsin breast cancer dataset.
- Evaluate the performance of the model using various metrics.
- Provide both a command-line interface (CLI) and a graphical user interface (GUI) for ease of use.
-
Clone the repository:
git clone https://github.com/yourusername/MultilayerPerceptron.git cd MultilayerPerceptron
-
Install the required dependencies:
pip install -r requirements.txt
The CLI allows you to train and evaluate the MLP model using command-line arguments.
To split the dataset into training and test sets, you can use the following command:
python mlp.py --split=0.25 --dataset=data/data.csv
To train and save the model and then save the plot of the results, you can use the following command:
python mlp.py --train --dataset=data/train.csv --layer 24 24 24 --batch_size=8 --learning_rate=0.00314 --initializer=he_uniform --activation=sigmoid --optimizer=nesterov --plot --patience 20
To evaluate the model on the test set, you can use the following command:
python mlp.py --predict=data/test.csv
The GUI provides an easy-to-use interface for interacting with the MLP model.
To start the GUI, run:
python gui.py
To tune the hyperparameters of the model, you can use the following command:
python HyperparameterTuner.py
The script does not take any arguments and will output the best hyperparameters found during the tuning process.
To visualize the data, you can use the following command:
python visualize_data.py
The project structure is as follows:
├── config
│ ├── config.py
├── data
│ ├── data.csv
│ ├── test.csv
│ └── train.csv
├── evaluation.py
├── gui.py
├── HyperparameterTuner.py
├── Layer.py
├── mlp.py
├── model.pkl
├── MultilayerPerceptron.py
├── NeuralNetwork.py
├── README.md
├── results
├── src
│ ├── activations.py
│ ├── losses.py
│ ├── metrics.py
│ ├── preprocessing.py
│ └── weight_initializers.py
└── visualize_data.py