The basic perceptron learning algorithm that explains how artificial neurons work
This repository implements a Perceptron Learning Algorithm to classify and predict data. It includes generating training and testing data, training a Perceptron model, tuning hyperparameters, and evaluating model performance using Mean Absolute Error (MAE).
The model is specifically designed to predict watermelon prices based on various attributes such as weight, juiciness, and external damage. The synthetic data generated simulates different watermelon characteristics, and the trained model uses these attributes to estimate the price. At the end of the process, the trained model allows users to input their own watermelon characteristics and receive a predicted price.
The Perceptron is a type of artificial neural network that is used for binary classification problems. It operates using a simple learning rule:
- Initialize weights randomly.
- For each data point in the training set:
- Repeat until convergence or for a fixed number of iterations.
├── data_generator.py # Generates synthetic training and testing data
├── tuning.py # Allows users to set hyperparameters
├── perceptron.py # Trains the Perceptron model
├── test_model.py # Evaluates the trained model
├── README.md # This documentation
Make sure you have Python installed along with NumPy and scikit-learn:
pip install numpy scikit-learn
Run perceptron.py
python perceptron.py
Type 1 to the question to create synthetic training and testing datasets:
Do you want to use your own data or generate new one for training data?
Type 1 - Generate
Type 2 - Don't generate
Do you want to use your own data or generate new one for testing data?
Type 1 - Generate
Type 2 - Don't generate
This will generate data_train.txt
and data_test.txt
files.
Type 1 to the question to define the learning rate, iteration count, and error tolerance:
Do you want to tune your model?
Type 1 - Tune
Type 2 - Use default settings
Model will be tested automatically to evaluate model performance:
This will compute the Mean Absolute Error (MAE) for predictions.
(default settings)
And finally:
We use Mean Absolute Error (MAE) to measure the model’s performance:
from sklearn.metrics import mean_absolute_error
mae = mean_absolute_error(y_true, y_pred)
- Lower MAE indicates better predictions.
- If MAE is close to zero, the model is highly accurate.
This project is open-source and available under the MIT License.