Specialty Digest

Global English editionLearners’ Study Dashboard — in development
The Knowledge Library for All

Clustering

nounMachine Learningalso cluster analysis, data clustering, k-means clustering

In one line

Clustering is an unsupervised machine learning task that groups data points so that items in the same group are more similar to each other than to items in other groups.

Clustering is a task in unsupervised learning in which an algorithm groups data points so that items in the same group, called a cluster, are more similar to one another than to items in other groups. No labels tell the algorithm what the groups should be. It discovers them from the data alone. Clustering is used to segment customers, organize documents, group genes with similar activity, compress images and find unusual items that fit no group. It is one of the most common tools for exploring data in machine learning and statistics.

How clustering works

Every clustering method rests on a notion of similarity, usually a distance between points. Euclidean distance, the straight-line distance, is most common, while cosine similarity is popular for text and Manhattan distance suits some data. The algorithm then arranges points into groups that are tight, with small distances inside, and well separated, with larger distances between groups. Because the right answer is not known in advance, clustering requires choices about the distance measure, the algorithm, the number of clusters and how the data are scaled. Features measured in large units can dominate distance, so scaling is nearly always needed.

Main clustering algorithms

### Centroid-based clustering

K-means is the best-known method. It picks k starting centers, assigns each point to the nearest center, moves each center to the mean of its points and repeats until the assignments stop changing. It is fast and simple but assumes roughly round clusters of similar size and needs k in advance. Variants include k-medoids, which uses real data points as centers and resists outliers, and k-means++, which chooses better starting points.

### Hierarchical clustering

Agglomerative clustering starts with each point as its own cluster and repeatedly merges the two closest clusters, producing a tree called a dendrogram. Cutting the tree at a chosen height gives a set of clusters. It does not need k in advance and reveals structure at several levels, but it is slow for very large data. Divisive clustering works in the opposite direction by splitting.

### Density-based clustering

DBSCAN, introduced in 1996, defines clusters as dense regions separated by sparse ones. Points in low-density areas are labeled noise. It finds clusters of any shape and detects outliers but struggles when clusters have very different densities. HDBSCAN improves on this.

### Model-based clustering

Gaussian mixture models assume that data come from a mix of bell-shaped distributions and estimate their parameters with the expectation-maximization algorithm. Each point gets a probability of belonging to every cluster, which is called soft clustering, in contrast to hard clustering where each point has exactly one cluster.

### Other methods

Spectral clustering uses the structure of a similarity graph and can find non-convex clusters. Mean shift finds peaks in the data density. Self-organizing maps arrange clusters on a grid. Deep clustering combines neural network embeddings with clustering objectives for images and text.

Choosing the number of clusters

When k must be chosen, analysts use heuristics. The elbow method plots the within-cluster variation against k and looks for a bend after which gains are small. The silhouette score measures how well each point fits its own cluster compared with the nearest other cluster, with values near one indicating clear structure. The gap statistic compares the result with random data. In practice, domain knowledge matters as much, since a marketing team may prefer five segments because that is what it can act on.

Evaluating clusters

Internal measures, such as the silhouette score and the Davies-Bouldin index, judge compactness and separation without labels. External measures, such as the adjusted Rand index, compare clusters with known labels when they are available for testing. Stability checks run the algorithm on resampled data to see whether the same groups appear. The most important test is usefulness. Do the groups make sense to experts and support a decision?

Applications of clustering

Businesses segment customers by behavior to tailor offers and service. Search and news services group similar documents and stories. Biologists cluster genes, cells and species. Image processing uses clustering to reduce the number of colors and to segment regions. Geographers group locations with similar land use, and cities cluster incidents such as crimes or accidents to find hotspots. Cybersecurity teams cluster network behavior to find unusual activity, and recommendation systems group similar users or items. Clustering is also used to organize data before labeling and to generate features for other models.

Advantages and challenges

The method needs no labels, can reveal unexpected structure and is useful for exploration and compression. The challenges are real. Results depend on the algorithm, the distance measure and the settings. Clusters can be unstable, may not match meaningful categories and are hard to validate. High-dimensional data weaken distance measures, so dimensionality reduction is often applied first. Clustering on personal data can create groups that reinforce bias if used carelessly, so segments should be reviewed before they drive decisions about people.

A worked example

A streaming service wants to understand how subscribers use its platform. It builds features such as hours watched per week, share of documentaries, share of weekend viewing and number of devices, and standardizes them. It runs k-means for values of k from two to ten and finds that k equal to five gives a good silhouette score. Analysts study the groups and name them, such as weekend binge watchers, daily short-form viewers and occasional users. Product teams then design different recommendations and reminders for each group, and they re-run the clustering every quarter to see whether the groups shift.

Clustering vs. classification

Classification assigns items to predefined classes learned from labeled examples. Clustering has no predefined classes and no labels, and it discovers the groups itself. A common workflow is to cluster first to explore the data, name the clusters and then train a classifier to assign new items to them.

Practical tips for clustering

Scale the features, remove obvious outliers or use a robust method, and try several algorithms before settling. Visualize the result by reducing it to two dimensions, but do not trust the picture alone. Run the algorithm several times with different random starts, check that results are stable and write down what makes each cluster distinctive, such as the average values of its main features, so that non-technical colleagues can understand and use the segments.

FAQs

What is the most common clustering algorithm? K-means is the most widely used because it is simple and fast.

Is clustering supervised or unsupervised? Unsupervised, since it uses no labels.

How do I know if my clusters are good? Use measures such as the silhouette score, check stability and ask domain experts whether the groups are meaningful.

Key facts

  • Clustering is an unsupervised task that partitions data into groups of similar items without using labels.1
  • Major families include centroid-based methods such as k-means, hierarchical methods, density-based methods such as DBSCAN and model-based methods such as Gaussian mixtures.1
  • Cluster quality can be assessed with internal measures such as the silhouette score, since no ground truth labels exist.2

Related concepts

In the news

Quick checkWhy does k-means need the number of clusters to be chosen in advance?Show answer

Because the algorithm partitions the data into exactly k groups around k centers, so k must be set by the user or chosen with methods such as the elbow or silhouette analysis.

Sources

  1. scikit-learn, Clustering, https://scikit-learn.org/stable/modules/clustering.html
  2. Wikipedia, Cluster analysis, https://en.wikipedia.org/wiki/Cluster_analysis
  3. Jain, Murty and Flynn, Data Clustering: A Review, https://dl.acm.org/doi/10.1145/331499.331504

Editorially reviewed by Specialty Digest Editorial TeamLast reviewed November 17, 2026Researched and drafted with AI assistanceReport an issue