The Problem
Most real data arrives unlabeled. "Segment our customers," "find anomalous transactions," "group similar documents" — there's no answer key, so you can't compute accuracy. This unsettles people trained only on supervised metrics, and it's exactly why interviewers ask about it: clustering tests whether you can find and defend structure without a crutch. Done carelessly, you'll pick the wrong number of clusters, use the wrong algorithm for the shape of your data, and present noise as insight.
The Concept
The Challenge of Unsupervised Learning
In supervised learning, you have a safety net: labels tell you if your model is right or wrong. In unsupervised learning, there are no labels. You're asking the algorithm to find structure in data without being told what "correct" looks like. This means validation is fundamentally different — you can't compute accuracy because there's no ground truth. Instead, you rely on internal metrics (like silhouette score), domain knowledge, and visual inspection.
Two main families of unsupervised learning matter for ML engineering:
Clustering : group similar points (k-means, DBSCAN, hierarchical)
Dimensionality
reduction : compress features (PCA = linear; UMAP/t-SNE = nonlinear, for viz)
K-Means: The Algorithm and Its Assumptions
K-means is the most common clustering algorithm. It works by alternating two steps: (1) assign each point to the nearest centroid, and (2) move each centroid to the mean of its assigned points. Repeat until centroids stop moving. It's simple, fast, and works well when the data matches its assumptions.
The assumptions are also its failure modes: k-means assumes clusters are spherical (roughly circular), similar in size, and that you already know K (the number of clusters). It breaks on elongated shapes, clusters of very different densities, or data where the natural number of groups is unknown. Always scale features first — because k-means uses distance, a feature with large values will dominate the clustering.
DBSCAN fixes some of these issues: it finds clusters of arbitrary shape based on density, and it automatically marks low-density points as noise (outliers). You don't need to specify K — the algorithm discovers the number of clusters. But it's sensitive to the eps parameter (the density radius), and it struggles with clusters of very different densities.
The hard part isn't running the algorithm — it's that there's no ground truth, so validation relies on internal metrics and domain judgment, not a held-out accuracy.
You run k-means with K=3 and get a silhouette score of 0.72. With K=5 you get 0.68. With K=7 you get 0.61. What does this suggest?
Silhouette score measures how well each point fits its cluster vs the nearest other cluster (range -1 to 1). Higher = better separation. K=3 has the highest score, suggesting 3 is the most natural number of clusters for this data. But always validate with domain knowledge too.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Build It, Use It, Ship It, Evaluation, Exercises, Key Terms, Common Pitfalls, Interview Framing — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.