https://github.com/brunos3d/perceptron-even-odd-classifier
Interactive visualization of a perceptron neural network that classifies numbers as even or odd using JavaScript and D3.js.
https://github.com/brunos3d/perceptron-even-odd-classifier
ai bias even example input math neural-network neuron odd output perceptron sample study train
Last synced: 4 months ago
JSON representation
Interactive visualization of a perceptron neural network that classifies numbers as even or odd using JavaScript and D3.js.
- Host: GitHub
- URL: https://github.com/brunos3d/perceptron-even-odd-classifier
- Owner: brunos3d
- License: mit
- Created: 2025-06-05T16:28:37.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-06-05T16:38:24.000Z (12 months ago)
- Last Synced: 2025-06-05T17:31:44.739Z (12 months ago)
- Topics: ai, bias, even, example, input, math, neural-network, neuron, odd, output, perceptron, sample, study, train
- Language: HTML
- Homepage: https://brunos3d.github.io/perceptron-even-odd-classifier/
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ง Perceptron Visualizer: Even or Odd Classifier
This project is an interactive JavaScript visualization of a perceptron neural network that learns to classify numbers as **even or odd**. It provides a live, browser-based interface with visualization powered by D3.js.
---
## ๐ Features
- ๐ Input a number and test if it's classified as even or odd
- ๐ง Visual graph of the neural network structure (input โ neuron โ output)
- โ๏ธ Train automatically until reaching a target accuracy
- โน๏ธ Stop training at any time
- ๐ Live display of weights, bias, epoch count, and accuracy
---
## ๐ How It Works
This project uses a **single-layer perceptron** โ the simplest form of a neural network โ to classify numbers.
### ๐งฎ Perceptron Equation
The perceptron calculates the output `y` from input `x` using:
```
y = f(w * x + b)
```
Where:
- `x` is the input (in this case, `x = n % 2`)
- `w` is the weight
- `b` is the bias
- `f(z)` is the activation function:
```
f(z) = {
1, if z >= 0.5
0, otherwise
}
```
The output `y` will be:
- `1` for odd numbers
- `0` for even numbers
### ๐ Training Rule
Each epoch updates weights using the perceptron learning rule:
```
error = expected - predicted
w = w + learningRate * error * x
b = b + learningRate * error
```
This update process is repeated until the accuracy reaches a user-defined threshold.
---
## ๐จ Visualization
D3.js is used to render a simple visual of the perceptron network:
- **Input Node**
- **Single Neuron**
- **Output Node**
These are connected with lines and display live updates of current weights and bias.
---
## ๐งช Usage
1. Open `index.html` in your browser.
2. Enter a minimum accuracy (default: 90%).
3. Click **Train Perceptron**.
4. The network will train until the desired accuracy is reached.
5. Use **Test Number** to verify the classification of any integer.
6. Click **Stop Training** to manually halt training.
---
## ๐ Tech Stack
- **HTML5**
- **JavaScript (Vanilla)**
- **D3.js v7**
No build tools or dependencies required โ just open the HTML file in your browser.
---
## ๐ง Educational Purpose
This project is meant as a learning tool to demonstrate:
- How perceptrons work
- Binary classification
- Live training feedback
- Basic D3.js visualizations
---
## ๐ License
MIT โ Free to use, modify, and share.