Unsupervised Learning
Press Next → or use ← → arrow keys
Learning Without A Teacher
Unsupervised learning works exactly like that librarian. With no labels to guide it, it discovers the natural structure hidden in the data — groupings, compressed patterns, and oddities — purely from the data's own shape.
Supervised learning is given the answers and learns to reproduce them. Unsupervised learning gets no answers at all — it must find the questions and the structure on its own, which is exactly why it's so useful when labels are expensive or don't exist.
Supervised vs Unsupervised
| Aspect | Supervised Learning | Unsupervised Learning |
|---|---|---|
| Data | Labelled (X → y) | Unlabelled (X only) |
| Goal | Predict the known target | Discover hidden structure |
| Typical tasks | Classification, regression | Clustering, reduction, anomalies |
| Feedback | Right/wrong from labels | No ground truth |
| Example | Spam vs not-spam email | Group customers by behaviour |
The vast majority of real-world data arrives without labels — clicks, transactions, sensor readings, images. Unsupervised learning is how you extract value from it before anyone has spent the time (and money) to label a thing.
Three Families, Seven Workhorses
Clustering asks which things belong together. Dimensionality reduction asks what the essence of the data is. Anomaly detection asks what doesn't belong. Master these three questions and you've mapped the whole field.
K-Means — The City Planner
K-Means is fast and simple but you must pre-specify K, it assumes round, equal-sized clusters, it's thrown off by outliers, and — being distance-based — it demands scaled features. Great baseline; wrong tool for oddly-shaped clusters.
Points Snap To Their Nearest Centroid
Every point takes the colour of its nearest ★ centroid; every centroid then jumps to the middle of its coloured points. A few rounds of this and the clusters lock into place — no labels ever required.
How Many Clusters? Elbow & Silhouette
DBSCAN — Follows Density, Not Circles
DBSCAN grows clusters outward from dense "core" points — any point with at least
min_samples neighbours inside radius eps. It discovers the cluster
count on its own, traces arbitrary shapes like these rings, and explicitly labels leftover
points as noise (−1) — three things K-Means simply can't do.
Hierarchical — The Family Tree
Hierarchical clustering starts with each point alone and repeatedly merges the two closest groups (Ward linkage minimizes the variance added at each merge). The result is a dendrogram — slice it low for many clusters, high for few. One fit encodes all values of K, no re-running required.
Which Clustering Algorithm?
| Property | K-Means | DBSCAN | Hierarchical |
|---|---|---|---|
| Cluster count | Pre-specify K | Automatic | Cut after |
| Cluster shapes | Spherical only | Any shape | Flexible |
| Noise handling | No — assigns all | Yes — label −1 | Partial |
| Speed | Very fast | Slower (high-dim) | Slow on big data |
| Key parameters | n_clusters | eps, min_samples | linkage, cut height |
Reach for K-Means as a fast baseline on large, roughly-round clusters; DBSCAN when shapes are irregular, K is unknown, or noise must be flagged; and hierarchical when you want the full merge history or a dendrogram to explore.
Dimensionality Reduction — The Essence
t-SNE preserves local structure but distorts global distances, and it's stochastic and slow on big data. Use it to visualize and confirm clusters — never as features feeding a downstream model. For compression pipelines, use PCA or an autoencoder.
Isolation Forest — The Odd One Out
Build random trees that keep splitting the data. A normal point sits deep in the crowd and needs many splits to fence off; an anomaly stands alone and gets isolated in just one or two. The shorter the average path, the higher the anomaly score. On a fraud test it caught 19 of 20 frauds — 95% recall — with no labels at all.
Seven Algorithms At A Glance
| Algorithm | Best For | Scale? | Specify K? | Noise |
|---|---|---|---|---|
| K-Means | Fast baseline, spherical clusters | Yes | Yes | No |
| DBSCAN | Irregular shapes, unknown K | Yes | No | Yes |
| Hierarchical | Merge history, dendrograms | Rec. | Cut after | Partial |
| PCA | Linear reduction, denoising | Yes | n_components | Partial |
| t-SNE | 2-D/3-D visualization only | Yes | 2 or 3 | Partial |
| Autoencoder | Non-linear reduction, denoising | Yes | latent dim | Yes |
| Isolation Forest | Anomaly / fraud detection | No | contamination | Core |
Nearly everything distance- or variance-based needs scaling — the one exception is the tree-based Isolation Forest. Match the algorithm to the question: group, compress, or flag.
How Do You Score It With No Labels?
With no labels, there's no "accuracy" to check against. Metrics like silhouette and inertia measure compactness, not business value. Always pair the numbers with domain knowledge — and never trust cluster labels until you've profiled what each group actually contains.
End-To-End — Customer Segmentation
Clustering hands you group numbers; the value comes from step 5 — computing each segment's real-world averages (recency, spend, returns) and giving it a name a business can act on. A "VIP" segment with high spend and frequency is worth infinitely more than "cluster 0."
Where Unsupervised Learning Earns Its Keep
Seven Rules For Unsupervised Learning
'auto'.You've Mapped Unsupervised Learning
Unsupervised learning finds structure without labels through three questions — group it (clustering), compress it (dimensionality reduction), or flag it (anomaly detection). Scale your features, tune parameters honestly, judge results with domain knowledge, and fix your random seeds.
Deep-dive each algorithm on its own — K-Means and the elbow, DBSCAN, PCA, t-SNE / UMAP, and Isolation Forest — then build the full customer-segmentation pipeline end to end on a real dataset.
🧩 End of tutorial · Press ← to review, or click Restart