intermediatedata-mining

Clustering

Grouping similar things together when nobody told you what the groups were.

Key Points

What it is

Clustering is an unsupervised technique that groups data points so that points in the same group are more similar to each other than to points in other groups. Unlike classification, there are no predefined labels — the algorithm discovers the structure on its own. K-means, DBSCAN, and hierarchical clustering are the most common methods.

Why it exists

Sometimes you don't know what the groups are — you just suspect the data has structure. Customer segmentation is the classic case. You have behavioral data for millions of customers and you want to find natural groups that behave similarly, without pre-defining what those groups look like. Clustering lets the data suggest the answer.

Intuition

You have a bag of mixed coins from different countries and you have to sort them without knowing the countries in advance. You'd naturally group them by size, weight, and color. Coins that look similar end up in the same pile. K-means does exactly this — it groups data points so that the distance between points in a pile is small and the distance between piles is large. The 'features' are whatever attributes you give it, and 'similar' means close in that feature space.

How it works

  1. Choose k

    Decide how many clusters you want. Use the elbow method or silhouette score to guide the choice.

  2. Initialize centroids

    Pick k random points from the dataset as starting cluster centers.

  3. Assign points

    Each data point is assigned to the nearest centroid.

  4. Update centroids

    Recalculate each centroid as the mean of all points assigned to it.

  5. Repeat

    Repeat steps 3 and 4 until assignments stop changing or a maximum number of iterations is reached.

When to use

When not to use

Common mistakes

Notes

In practice

Clustering is used in customer segmentation, recommendation systems (finding users with similar taste), document organization, image segmentation, and bioinformatics (grouping genes by expression pattern). It also appears as a preprocessing step — run clustering first, then build a model per cluster.

Was this concept helpful?

Spot an error or gap? Suggest an edit →

Related concepts

anomaly-detectionassociation-rulestext-mining
Chirp at me!