Deepak Nalla
A perceptron trained from scratch in Python to recognize the digit 8 in ASCII art images — with zero external ML libraries.
The project is three standalone Python scripts that run in sequence. Each has exactly one job: prepare data, train weights, or classify a new image.
.###. #...# #...# .###. #...# #...# .###.
# → 1 · Each space/dot → 0A perceptron is the simplest possible neural network: one neuron that computes a weighted sum of its inputs and fires if the result crosses a threshold.
error = label − outputDraw on the 30×20 grid — click or drag to toggle pixels. The perceptron classifies in real time using a learned weight map.
Σ w·x + bias over all 600 pixels.
Positive sum → classified as 8.
Weights are shaped to recognize the figure-8 stroke pattern.
Misclassifications drop from 89 in epoch 0 to 0 by epoch 11, where the perceptron achieves perfect separation on the training set.
| Parameter | Value |
|---|---|
| Learning rate (η) | 0.10 |
| Max epochs | 15 |
| Feature dimensions | 600 |
| Bias | 0.10 |
| Positive samples (digit 8) | 86 |
| Negative samples (other) | 129 |
| Epochs to convergence | 11 |
perceptron/ ├── generate_features.py │ feature extraction ├── perceptron_train.py │ training loop ├── evaluate.py │ classify new image ├── features.csv ├── weights.csv ├── requirements.txt └── data/ ├── train8/ 86 positives ├── trainOthers/ 129 negatives └── test/ evaluation images
# Install dependencies pip install -r requirements.txt # 1. Generate feature matrix from training images python3 generate_features.py # 2. Train the perceptron (saves weights.csv) python3 perceptron_train.py # 3. Classify a test image cp data/test/8.txt data/test/img.txt python3 evaluate.py # → It is a 8