How to use the k-means clustering calculator
- Paste your data as rows of numbers, one point per line with the same number of columns on every line, separated by commas, spaces or tabs.
- Set the number of clusters and a seed. The same seed always gives the same answer. Tick the box to standardize each column first when the columns use very different scales.
- Open the advanced options to change the largest k in the comparison table and the number of restarts.
- Read the cluster centers and sizes, the within-cluster sum of squares and the average silhouette, and compare different values of k in the table.
Formula
assign each point to the nearest center, then move each center to the mean of its points, until nothing changes
within-cluster sum of squares = sum of squared distances from each point to its center
silhouette of a point = (b - a) / max(a, b)
a = mean distance to its own cluster, b = smallest mean distance to another cluster
Starting centers are chosen by k-means++, which picks far-apart points with higher probability. The best of several restarts is kept.
Three clear groups
Twelve points fall into three groups of four near (1.1, 1.0), (5.1, 5.0) and (9.0, 1.1). With k = 3 the within-cluster sum of squares is 0.5250 and the average silhouette is 0.9441. With k = 2 the sum of squares is 62.935 and the silhouette 0.6493, and with k = 4 the sum is 0.3900.
The jump from 62.9 to 0.525 when k goes from 2 to 3, followed by small gains after that, is the elbow that points to three clusters. With k = 1 the sum of squares is 169.0717.
Choosing the number of clusters
The sum of squares always falls as k grows, down to zero when every point is its own cluster, so a lower number alone does not mean a better split. Look for the elbow where the gains become small, and for a high silhouette. A silhouette near 1 means points sit well inside their clusters, near 0 means they sit on the border, and below 0 suggests a point is in the wrong cluster.
K-means finds one local best split, not always the best possible one. Restarts and a fixed seed make the result repeatable. Different seeds can give different splits when the groups are not clear, which is itself useful information.
Scale and shape
Distances are plain straight-line distances, so a column measured in thousands outweighs one measured in tenths. Standardizing puts every column on the same scale. K-means also favors round, similar-sized groups. For summaries of single columns, try the descriptive statistics calculator or CSV statistics, and to fit a line through two columns see the linear regression calculator. The convex hull calculator outlines a cluster of two-column points.
Assumptions and limits
- Straight-line (Euclidean) distance is used. Categories must be turned into numbers before pasting.
- Up to 1,000 rows, 10 columns, k from 2 to 10 and 50 restarts are accepted.
- The silhouette needs at least two clusters, and a cluster with one point scores 0.
- The cluster numbers are ordered by the first column of each center, so they stay stable between runs.
Frequently asked questions
Why does the same data give different clusters with another seed?
K-means starts from random centers and stops at the nearest good split. When the groups are well separated every start reaches the same answer. When they overlap, different starts can end in different splits, and the best sum of squares among the restarts is kept.
Should I standardize my columns?
Standardize when the columns have different units or very different ranges, such as age in years and income in dollars. Leave it off when all columns are on the same scale, such as x and y positions.
What does an empty cluster mean?
It can happen when k is larger than the natural number of groups. The tool moves the empty center to the point farthest from its center and carries on, so every cluster ends up with at least one point.
Can I download the cluster for each row?
Yes. The CSV download lists every row with its cluster number. The page itself shows the first 60 rows to keep the result readable.