Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Single Perceptron Training — Sonar Dataset (Mines vs. Rocks)

A hands-on machine learning notebook that trains a single Perceptron (scikit-learn) on the UCI Sonar (Connectionist Bench) dataset, and uses the results as evidence for why a single perceptron is not enough for most real-world problems — and why deep learning moved on to multi-layer perceptrons (MLPs).


🎯 Goal

Show, with data and visuals rather than just theory, that:

A single perceptron can only learn a linear (straight-line / flat-plane) decision boundary. Real-world data is often not linearly separable, so a single perceptron underperforms on it — which is exactly why researchers stacked perceptrons into multi-layer networks with non-linear activations.


📊 Dataset


🧭 Notebook walkthrough

  1. Load the data:- fetch the dataset via ucimlrepo.
  2. Explore:- first look at features/target, shape, dtypes, summary stats.
  3. Data quality checks:- missing values, duplicates, class balance.
  4. Encode the target:- convert M/R labels to 0/1.
  5. Correlation analysis:- heatmap of all 60 features, then drop redundant (highly correlated) ones to get a smaller, cleaner feature set.
  6. Visualize distributions:- histograms and class-wise density plots to check, visually, how separable Mine vs. Rock really are.
  7. Train a single Perceptron:- on two chosen features (so the decision boundary can be drawn in 2D) and plot the resulting straight decision line against the data.
  8. Evidence: accuracy & confusion matrix:- quantify how many points the straight line actually gets wrong.
  9. Evidence: MLP comparison:- train a small multi-layer perceptron (with a hidden layer) on the same two features. Since an MLP can bend its boundary, a higher score there isolates the perceptron's linearity as the actual bottleneck.
  10. Conclusion:- ties the visual and numeric evidence together into the final takeaway.

🔑 Key takeaway

A single perceptron is a great teaching tool for understanding how one artificial neuron learns — but it caps out at problems that are linearly separable. Once data gets messy and overlapping (like real sonar readings), you need multiple layers of neurons with non-linear activation functions to bend the decision boundary around the data. That gap is the entire reason the multi-layer perceptron (MLP) — and modern deep learning — exists.


🛠️ Requirements

pandas
numpy
matplotlib
seaborn
scikit-learn
ucimlrepo

Install with:

pip install pandas numpy matplotlib seaborn scikit-learn ucimlrepo

▶️ Running the notebook

Open Single-Perceptron-Experiment.ipynb in Jupyter or VS Code and run all cells top to bottom. The dataset is fetched live from the UCI repository, so an internet connection is required.


About

A single Perceptron trained on real sonar data — visual + numeric proof of why linear models fail and why Multi-Layer Perceptrons exist.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages