Unsupervised Learning

What is clustering in unsupervised learning?

Clustering groups data points by similarity without labels. Learn how K-means, hierarchical clustering and DBSCAN work, with examples and common pitfalls.

On this page
  1. A simple picture
  2. How similarity is measured
  3. Main clustering methods
  4. Choosing how many clusters
  5. Real-world uses
  6. Limits
  7. A practical sequence

Clustering is an unsupervised learning task that groups data points so that points in the same group are more similar to each other than to points in other groups. No labels are given. The algorithm decides what counts as similar, usually by measuring the distance between points across their features.

A simple picture

Imagine a scatter plot of customers, with how often each person buys on one axis and how much they spend per visit on the other. The points may form a few loose clouds. A clustering algorithm can find those clouds without being told how many there are. A person may later describe one cloud as occasional big spenders, but that description comes from the person, not the algorithm.

Questions like “What is unsupervised classification?” get a similar answer: the algorithm forms the groups, and people name them.

How similarity is measured

Each item is a row of numbers called features. The most common measure is Euclidean distance, the straight-line distance between two points in feature space. Every feature counts toward that distance, so a feature measured in large units can swamp the others. Scaling the features, for example so each one has a mean of zero and a standard deviation of one, is a common fix. Categorical features need different handling, such as encoding them as numbers or using a distance measure designed for mixed data.

Scaling is one of the basic preprocessing steps, and it can change results a lot. It is worth checking before you trust any clusters.

Main clustering methods

  • K-means needs you to choose k. It alternates between assigning points to the nearest center and moving each center to the average of its points. It works best when clusters are roughly round and similar in size.
  • Hierarchical clustering builds a tree of merges. You pick a level to cut the tree, so you don’t have to fix k in advance.
  • DBSCAN finds dense regions and marks sparse points as noise. It can handle irregular shapes, but two settings control what counts as dense.
  • Gaussian mixture models give each point a probability of belonging to each cluster, which is useful when groups overlap.

Choosing how many clusters

Many methods need you to decide how many clusters to look for. Two common helpers are:

  • The elbow method plots how tight the clusters are for different values of k. Look for a bend, where adding more clusters stops helping much.
  • The silhouette score measures how well each point fits its own cluster compared with the nearest other cluster. Higher average scores generally mean better separation.

Neither gives a single correct answer. The best choice depends on what you plan to do with the groups.

Real-world uses

  • Customer segmentation for marketing or service planning
  • Grouping documents by topic when no topic labels exist
  • Reducing the number of colors in an image
  • Grouping sensor readings into typical operating modes
  • Flagging points that fit no group, which can point to unusual cases

Limits

  • Results depend on the features you choose and how you scale them.
  • K-means assumes roughly round clusters and can settle on a poor solution, which is why several random starts are common.
  • As the number of features grows, distances can become less informative, which makes high-dimensional data harder to cluster.
  • There are no answer labels to check against, so groups should be tested for stability and reviewed by someone who knows the data.

A practical sequence

  1. Clean the data and scale the features.
  2. Try K-means over a range of k values as a baseline.
  3. Compare silhouette scores and check whether the groups hold up on a second run.
  4. Inspect each group’s typical members.
  5. If the groups look wrong, try another method, such as hierarchical clustering or DBSCAN.

The complete guide to unsupervised learning

Different Types of Unsupervised Machine Learning Algorithms
Read the guide

Keep exploring

Guides from other topics

All topics →