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:
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.
Related Resources
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.
For additional information on related topics, take a look at the following resources:
- ChromaDB: Embeddings and Vector Databases in Python (Tutorial)
- Vector Databases and Embeddings With ChromaDB (Course)
- The k-Nearest Neighbors (kNN) Algorithm in Python (Tutorial)
- Split Your Dataset With scikit-learn's train_test_split() (Tutorial)
- K-Means Clustering in Python: A Practical Guide (Quiz)
- Embeddings and Vector Databases With ChromaDB (Quiz)
- Using k-Nearest Neighbors (kNN) in Python (Course)
- Splitting Datasets With scikit-learn and train_test_split() (Course)
- Split Your Dataset With scikit-learn's train_test_split() (Quiz)
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