Skip to content

clustering

Clustering is the machine learning task of grouping unlabeled data points so that points in the same group, or cluster, are more similar to each other than to points in other groups. It’s a core task of unsupervised learning, since no example arrives with a correct group attached.

Similarity usually means a short distance between vectors, so the choice of features and distance measure shapes the result as much as the algorithm does. Common families differ in what they treat as a cluster:

  • Centroid-based: K-means places a fixed number of centers and assigns each point to the nearest one. It needs the cluster count up front and favors round, evenly sized groups.
  • Density-based: DBSCAN and HDBSCAN grow clusters from dense regions, find the cluster count on their own, and label sparse points as noise.
  • Hierarchical: Agglomerative clustering repeatedly merges the closest groups into a tree, called a dendrogram, that can be cut at any level.
  • Distribution-based: Gaussian mixture models give each point a probability of belonging to every cluster rather than a single hard label.

Switch between K-means and DBSCAN on the same points below to see how a centroid-based and a density-based method can group identical data differently:

Interactive diagram — enable JavaScript to view.

With no ground truth to compare against, results are judged by internal scores such as the silhouette coefficient, or by whether the groups make sense to a person reading them.

In LLM work, clustering usually runs on embeddings. It groups near-duplicate documents before training and surfaces recurring themes in user prompts or support tickets.

Topic-modeling libraries such as BERTopic chain an embedding model, a dimensionality reduction step, and HDBSCAN to turn raw text into labeled topics.

K-Means Clustering in Python: A Practical Guide

Tutorial

K-Means Clustering in Python: A Practical Guide

Learn how to perform k-means clustering in Python with scikit-learn, choose the right number of clusters, and build an end-to-end clustering pipeline.

advanced algorithms data-science machine-learning

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Martin Breuss • Updated Nov. 14, 2026