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).
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.
- Source: UCI Machine Learning Repository — Connectionist Bench (Sonar, Mines vs. Rocks)
- Samples: 208 sonar returns
- Features: 60 numeric "energy band" readings per sample
- Target:
M(Mine) orR(Rock)
- Load the data:- fetch the dataset via
ucimlrepo. - Explore:- first look at features/target, shape, dtypes, summary stats.
- Data quality checks:- missing values, duplicates, class balance.
- Encode the target:- convert
M/Rlabels to0/1. - Correlation analysis:- heatmap of all 60 features, then drop redundant (highly correlated) ones to get a smaller, cleaner feature set.
- Visualize distributions:- histograms and class-wise density plots to check, visually, how separable Mine vs. Rock really are.
- 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.
- Evidence: accuracy & confusion matrix:- quantify how many points the straight line actually gets wrong.
- 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.
- Conclusion:- ties the visual and numeric evidence together into the final 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.
pandas
numpy
matplotlib
seaborn
scikit-learn
ucimlrepo
Install with:
pip install pandas numpy matplotlib seaborn scikit-learn ucimlrepoOpen 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.