الانتقال إلى المحتوى
Machine LearningUnsupervised Learning· 7 دقائق للقراءة

Clustering Doesn't Discover 'True' Groups: K-Means Assumptions Explained

Every clustering method returns groups, even from noise. What it returns follows its own idea of a group.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
  • scikit-learn 1.9
محتويات المقال

A marketing team runs k-means on two scaled columns, monthly spend and visit frequency. They try k from 2 to 6 and keep k=4, because it has the best silhouette score: 0.413. Four personas get names, photos and a slide deck. But the data in the first script below is uniform noise: customers spread evenly, with no groups at all. k-means didn't discover four segments. It cut a square into four pieces, the way it would cut anything.

The common misconception

"Clustering reveals the natural, true groups that exist in the data." It's an easy belief to hold:

  • It's called unsupervised learning, which sounds like the algorithm finds structure with no human assumptions.
  • The output looks authoritative: every row gets a label, every group gets a center, and a metric gives a number.
  • On textbook demos with well-separated round blobs, really does recover the groups that generated the data, exactly.

The half-truth: when groups are compact, round, similar in spread and well apart, k-means finds them. But that's the data agreeing with an assumption the algorithm made in advance. Change the data, and the same algorithm still answers, just as confidently.

What actually happens

A clustering algorithm doesn't look for groups in general. It optimizes one specific definition of a group, and it returns the best answer under that definition, whether or not the data has that shape.

Every algorithm brings its own definition of a group

k-means places k centers to minimize inertia, the sum of squared distances from each point to its nearest center. scikit-learn's guide spells out the price: inertia assumes clusters are convex and isotropic, so k-means "responds poorly to elongated clusters, or manifolds with irregular shapes." Its k-means assumptions example adds that k-means behaves like a mixture of Gaussians that all share the same variance, so groups with very different spreads also break it.

Other methods define a group differently. DBSCAN treats clusters as areas of high density separated by areas of low density, so they can take any shape. A Gaussian mixture fits ellipses, each with its own shape and spread. Agglomerative clustering depends on the linkage you choose. None of these definitions is the true one; each fits some data and not other data.

It always returns k groups

For k-means, k is an input, not a finding: Google's clustering course lists "k must be chosen manually" as its first disadvantage. scikit-learn's assumptions example goes further: in a real setting there is no uniquely defined true number of clusters, and the right number has to come from data-based criteria and knowledge of the intended goal. Its algorithm-comparison example even includes a "null" dataset, homogeneous data with no good clustering. Given a k, k-means splits it anyway, as the first script shows.

Scores share the algorithm's assumptions

Without known labels, people judge clusters with internal scores such as the . For each point it compares a, the mean distance to its own cluster, with b, the mean distance to the next nearest cluster: s = (b − a) / max(a, b). scikit-learn lists its drawback plainly: it's generally higher for convex clusters than for density-based clusters like DBSCAN's. In other words, silhouette and k-means share an idea of what a cluster is, so silhouette tends to reward k-means.

Python
import numpy as npfrom sklearn.cluster import KMeansfrom sklearn.metrics import silhouette_scorerng = np.random.default_rng(0)customers = rng.uniform(size=(1000, 2))  # scaled spend and visits, no groupsfor k in range(2, 7):    labels = KMeans(n_clusters=k, random_state=0).fit_predict(customers)    print(f"k={k}: silhouette {silhouette_score(customers, labels):.3f}")# k=2: silhouette 0.360# k=3: silhouette 0.380# k=4: silhouette 0.413  <- "we found 4 customer segments"# k=5: silhouette 0.382# k=6: silhouette 0.379

On the noise, silhouette peaks at k=4 with 0.413, a number anyone could present as structure. On the crescents, k-means earns the higher silhouette, 0.490 against 0.335, yet its groups barely match the real crescents: an adjusted Rand index of 0.253, where random labels score close to 0 and identical groupings score 1.0. DBSCAN, whose definition of a group fits crescents, matches them exactly. The silhouette preferred the wrong answer, because it measures the k-means idea of a cluster, not the truth.

Your features decide the distances

k-means compares rows with Euclidean distance, so the columns you include, and their units, decide the groups. Leave income in dollars next to age in years and income alone draws the boundaries; that's why feature scaling matters for distance-based models. Add many weak columns and distances inflate, the curse of dimensionality: both scikit-learn and Google suggest reducing dimensions, for example with PCA, before k-means.

And the starting point

k-means always converges, but possibly to a local minimum that depends on the initial centers. scikit-learn uses k-means++ initialization by default and lets you run several starts with n_init. Google adds that outliers can drag centers or get a cluster of their own.

k-means assumesWhen the data disagreesConsider
Round, convex groupsElongated or curved groups get cut acrossGaussianMixture for ellipses, DBSCAN for any shape
Similar spread in every groupA wide group loses points to a tight neighborGaussianMixture
You know kIt returns k groups anyway, even from noiseThe decision's needs, stability and null checks
Every point belongs to a groupOutliers drag centers or get their own clusterDBSCAN, which labels noise as -1
Columns on comparable scalesThe widest-ranging column draws the boundariesDeliberate scaling and feature choice

How to apply it in your project

  1. Define a group before you clusterWrite down what the groups are for: customers who respond alike to a campaign, stores with similar demand. That decides the features, the distance and the algorithm.
  2. Pick a method whose definition fitsUse k-means for compact, similar-sized groups, GaussianMixture for elliptical ones, DBSCAN for dense regions of any shape with outliers. Scale and select features deliberately.
  3. Compare against a nullRun the same pipeline on column-shuffled data. Structure that doesn't beat the null isn't structure.
  4. Check stabilityRerun with different seeds and on bootstrap samples, and compare the labelings with adjusted_rand_score. Groups that change on every run aren't a property of the data.
  5. Validate outside the clusteringCheck the groups against something the algorithm never saw: a labeled sample, or a downstream outcome, such as whether segments really respond differently to the campaign.

Key takeaways

  • Clustering always returns groups: on uniform noise, k-means "found" 4 with a silhouette of 0.413.
  • Each algorithm defines a group; k-means assumes round, convex groups with similar spread.
  • Internal scores share those assumptions: silhouette preferred k-means (0.490) over DBSCAN (0.335) on crescents that only DBSCAN recovered.
  • Decide what a group means for your decision, then test the clusters against a null, for stability, and against outside evidence.

📚 المصادر

  1. Demonstration of k-means assumptions — scikit-learn examples
  2. Clustering — scikit-learn User Guide
  3. Comparing different clustering algorithms on toy datasets — scikit-learn examples
  4. Advantages and disadvantages of k-means — Google Machine Learning Clustering course

التعليقات (0)