Skip to content

About

Single-layer perceptron built from scratch in pure Python — manual weight configuration, step & sigmoid activation functions, linear decision boundary visualization. No libraries

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

🧠 Perceptron from Scratch

An interactive single-layer perceptron built in pure Python, capable of classifying linearly separable data and visualizing results in real time through the console.


📌 Description

This project implements a simple perceptron from scratch without the use of any machine learning libraries. The program allows the user to load their own dataset, manually configure weights and bias, select an activation function, and instantly visualize the perceptron's performance through comparative scatter plots.

This project serves as the foundation for a Multilayer Perceptron (MLP) implementation with backpropagation.


🛠️ Tech Stack

Python Matplotlib No ML Frameworks

  • Python 3.x — no ML libraries used (fully manual implementation)
  • Matplotlib — only external dependency, used for visualization

✨ Features

  • 📂 Load data from custom CSV files via console
  • ⚙️ Manual configuration of weights (w) and bias (b)
  • 🔘 Choose an activation function at runtime:
    • Step Function
    • Sigmoid Function
  • 📊 Automatic generation of 3 side-by-side plots using matplotlib:
    • Expected values (ground truth)
    • Predicted values by the perceptron
    • Error map (green / yellow / red)
  • 🔁 Ability to test different weights without restarting the program

🗂️ Project Structure

perceptron/
│
├── main.py              # Entry point of the program
├── perceptron.py        # Perceptron logic (weighted sum, activation, execution)
├── data.py             # CSV loading and parsing
├── plots.py           # Visualization with matplotlib
│
├── fuzzy_separables.csv     # Linearly separable dataset (fuzzy)
└── no_separables.csv        # Linearly non-separable dataset

📊 Visualizations

Plot Description
1. Expected Value Ground truth classification from the dataset
2. Predicted Value Classification computed by the perceptron
3. Error Map Green: low error (<5%) · Yellow: medium (<15%) · Red: high (>15%)

The decision boundary (dashed line) is automatically calculated from the input weights and bias.


🚀 Getting Started

1. Clone the repository

git clone https://github.com/iarondon3/Perceptron.git
cd Perceptron

2. Install the dependency

pip install matplotlib

3. Run the program

python main.py

Program Flow

1. Enter the path to your CSV file
2. Select an activation function (Step or Sigmoid)
3. Enter the bias value
4. Enter a weight for each input variable
5. The perceptron computes Z and generates predictions
6. Three comparative plots are displayed
7. Try new weights or exit the program

📁 File Format

The CSV file must include headers in the first row. The first n-1 columns are inputs and the last column is the expected output (0 or 1):

x1,x2,output
2.5,1.3,1
0.8,3.1,0
...

🧮 Mathematical Foundation

Weighted Sum:

Z = (w1 · x1) + (w2 · x2) + ... + b

Activation Functions:

  • Step Function: returns 1 if Z > 0, 0 otherwise
  • Sigmoid: σ(Z) = 1 / (1 + e^(-Z))

⚠️ Known limitation: the perceptron cannot separate linearly non-separable data. This is an expected and demonstrated behavior using the no_separables.csv dataset.


👩‍💻 About the Author

Isabella Rondón | Business Economist & Data Analyst

LinkedIn GitHub Portfolio

About

Single-layer perceptron built from scratch in pure Python — manual weight configuration, step & sigmoid activation functions, linear decision boundary visualization. No libraries

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages