In plain words
Give a computer a pile of data with no labels, such as thousands of shoppers, songs or news stories, and ask it to put alike things together. That is clustering. It is the most common kind of unsupervised learning.
The computer measures how close items are to each other, based on their details. Shoppers who visit at similar times and spend similar amounts end up near each other. Clusters are the crowded patches.
The computer does not know what a cluster means. People look at each group and name it: weekend families, late night snackers. Clustering is used to group customers, organise photos, spot unusual activity and give a messy dataset some shape.
Everyday example
Placing three milk depots in a town
A dairy wants three depots for its 300 customers. It drops three pins on the map at random and assigns each home to its nearest pin. Then it moves each pin to the middle of the homes assigned to it, and reassigns. After a few rounds the pins stop moving. That is exactly how k-means, the best known clustering method, works.
Where the example breaks: The dairy knows roads, rivers and traffic matter. Clustering only uses the distances it is given, and it will happily produce groups even when the data has no real groups in it.
How it actually works
Clustering needs two choices: how to measure similarity between items, and which method to use to form the groups.
Measure similarity
Each item becomes a list of numbers, its features. Similarity is usually distance in that space. For text and images, items are often first turned into embeddings so that similar meaning means short distance.
k-means, step 1
Choose k, the number of groups. Place k centres, called centroids, then assign every item to its nearest centroid.
k-means, step 2
Move each centroid to the average position of the items assigned to it. Repeat both steps until little changes. The method aims to make the total squared distance from items to their centroids as small as possible.
Other methods
Hierarchical clustering builds a tree of groups inside groups. Density-based methods find clusters of any shape and mark sparse points as outliers. k-means is the most widely used centroid-based method.
Judging the result
There is no answer key, so quality is judged by how tight and separate groups are and, above all, whether they are useful. Choosing k is part of the art.
- Type of learning
- Unsupervised: no labels needed
- Best known method
- k-means: the standard algorithm was proposed by Stuart Lloyd at Bell Labs in 1957 (published 1982); the name is from James MacQueen, 1967, and the idea goes back to Hugo Steinhaus, 1956
- Centroid
- The centre of a cluster; usually not one of the actual items
- Used for
- Customer segments, grouping songs or news, image compression, spotting fraud and outliers
Questions people ask
What is the difference between clustering and classification?
Classification learns categories that people defined in advance, from labelled examples. Clustering gets no labels and discovers groups by itself. Classification asks which known box an item belongs in; clustering asks what boxes exist.
How does k-means clustering work?
Pick how many groups you want. Drop that many centre points, assign every item to its nearest centre, then move each centre to the middle of its items. Repeat until the centres stop moving.
How do you choose the number of clusters?
There is no single right answer. People try several values and look for the point where adding another cluster stops making groups much tighter, or simply pick the number that is useful, like three sweater sizes.
Where is clustering used in real life?
Shops group customers for offers, music apps group songs by sound, news apps group stories about the same event, and banks and platforms look for activity that fits no normal group, a common sign of fraud or abuse.