K-Means Clustering calculator
Perform k-means clustering online. Find optimal centroids, plot results, and evaluate using elbow plots and silhouette scores.
What it does
You're hoping the data reveals groups you haven't defined yet — that's unsupervised clustering, not a model that assigns cases to labels you already know, so cases are grouped directly from the chosen features' similarity structure.
When to use it
Each case gets a cluster label describing which group of similar cases it falls into with respect to the features you selected; cluster profiles describe typical, overlapping values per group, not hard boundaries.
Worked example
You have 5,000 customers and want to know whether they fall into a handful of natural types. You give k-means their spend, purchase frequency and average basket size, ask for four groups, and it returns four — because you asked for four. It will always find the number you request, so the judgement is yours: check whether the groups are actually separated before naming them.
Cautions
- Clustering cannot confirm the groups are 'real' in any objective sense. It will partition data with no group structure at all just as readily as data that has some, and nothing in the output distinguishes the two. It cannot name what a cluster 'means' from centroids alone, and the result describes structure with respect to the features you chose only — change the features and the clusters change.
- Because a clustering algorithm ALWAYS returns clusters whether or not real structure exists, the result reports a silhouette score and an elbow curve across candidate k so the cut can be judged. Two further checks are NOT computed here and remain yours to make: whether the solution is stable across resamples and seeds, and whether the discovered groups differ on variables that were not used to build them. The second is the one that decides whether a partition is real.
Alternatives
- Classification (assigning to known groups) — Classification needs labelled groups to learn from; you don't have labels to assign here, only a hope that structure exists — clustering doesn't require labels.
- Reporting the cluster split on the same features used to build it as a finding — Groups built from a feature set will always differ on that same feature set by construction — that comparison is circular and proves nothing about whether the clusters are real.
How to read the output
- The cluster assignment and sizes
- Every point is placed in exactly one cluster; no point is left out. Clustering always returns clusters, whether or not any exist — k-means will happily cut uniform noise into four tidy pieces. A partition is a hypothesis, not a finding: check the groups differ on a variable you did NOT cluster on before describing them as real.
- Silhouette
- Per point, how much closer it sits to its own cluster than to the nearest other one, averaged over the data. Roughly: above 0.5 is a clean separation, 0.25–0.5 is weak structure, below 0.25 is not a partition worth describing. It measures whether the CUT is clean, not whether the groups mean anything. A high silhouette on variables that are three versions of the same measurement describes your column list, not your subjects.
- The elbow curve (inertia against k)
- Total within-cluster distance for k = 1 to 8. It always falls as k rises; the useful signal is the bend, where extra clusters stop buying much. It falls monotonically by construction, so 'lower is better' would always choose the largest k. If there is no visible bend, that is evidence against a natural number of clusters — not a licence to pick the end of the curve.
- Whether the data were scaled
- Every method here works on distances, and a distance adds up your columns' units. Standardizing puts each variable on the same footing before that sum is taken. Unscaled, the variable with the largest numeric range silently becomes the clustering. Income in pounds against age in years is a clustering of income. Turn scaling off only when the raw units are genuinely comparable and you mean to keep their relative weight.
- Cluster shape
- K-means draws straight boundaries halfway between centres, so it finds roughly spherical, similarly-sized blobs. It will cut an elongated or crescent-shaped cluster in half rather than recognise it, and it splits one large group before it merges two small ones. If the scatter shows shapes rather than blobs, the partition is an artefact of the method.
How this calculator is validated · Which statistical test should I use?