clustering
Clustering is the unsupervised task of grouping data points so that items in the same group are more similar to each other than to items in any other group — with no labels telling the model what the groups should be or how many there should even be. The algorithm has to discover structure purely from how points relate to each other in feature space, which is exactly why clustering is the go-to tool whenever a team suspects there's meaningful structure in a dataset but doesn't yet know what that structure looks like. At a high level, a typical clustering run looks like this:
K-means and DBSCAN solve the same problem with fundamentally different assumptions about what a cluster even is, which is why picking the wrong one for a dataset's actual shape produces confidently wrong results. K-means assumes clusters are roughly round, similarly sized blobs, and requires specifying the number of clusters, k, in advance — it works by repeatedly assigning each point to its nearest of k cluster centers and then recomputing those centers, converging quickly but failing badly on clusters with irregular shapes or very different densities. DBSCAN instead groups points based on local density, requiring no predetermined cluster count and naturally handling arbitrarily shaped clusters, with the added advantage of explicitly labeling sparse, isolated points as noise rather than forcing them into the nearest cluster regardless of fit.
Choosing the right number of clusters for k-means is a real methodological problem, not a parameter you can just guess correctly on the first try. The elbow method plots the within-cluster error against different values of k and looks for the point where adding more clusters stops meaningfully reducing error — a visible "elbow" in that curve — while the silhouette score instead measures how well-separated and internally cohesive each proposed clustering actually is, giving a single number per candidate k that can be compared directly without relying on a subjective visual read. Neither method is foolproof, and in practice teams often run several values of k and sanity-check whether the resulting clusters correspond to anything meaningful in the real-world problem, since a mathematically optimal k can still produce groupings nobody can act on.
Clustering's real industrial value often isn't the grouping itself, but what the grouping reveals about a dataset nobody had fully characterized yet. Grouping customer transaction patterns can surface segments a marketing team never explicitly defined; clustering a fab's defect-image signatures can reveal a previously unnamed failure mode simply because enough defects with a shared visual signature happened to group together, prompting an engineer to go investigate what physical mechanism actually produces that cluster. This exploratory role — finding structure worth naming, rather than confirming structure already assumed — is what distinguishes clustering's actual use case from a classification task that already knows what the categories are.
Read clustering as the tool for the moment before you know what the categories even are: it makes no promises about matching any ground truth, because there is no ground truth to check against, and its entire value comes from surfacing structure a human can then inspect, name, and decide whether to act on.