✕
CN EN

Dimensionality reduction & clustering / k-means clustering

Your data stays in your browser: files are read and processed on your device, never uploaded to any server, and cleared when you close the page. Free, no sign-in.

How to read it

k-means clustering

k-means splits samples into k clusters so that the sum of squared distances from each sample to its cluster centre (within-cluster sum of squares) is minimal. The scatter plot shows samples on the first two principal components, coloured by cluster.

Choosing k: in the elbow plot the within-cluster sum of squares falls as k grows, and the point where the fall levels off (the “elbow”) is a common candidate; a higher silhouette width (−1 to 1) means better-separated clusters. Both are guides only; decide with the biological context.

Tick z-scoring when variables have different units. k-means assumes roughly spherical clusters of similar size and is sensitive to outliers.

The algorithm starts from random centres: this tool uses k-means++ initialisation with several restarts and keeps the lowest sum of squares; with a fixed seed results are reproducible. Cluster numbers have no intrinsic order.

With a known group column, the adjusted Rand index (ARI; 1 = identical, about 0 = random) measures agreement between clusters and groups.

Method

Lloyd S. (1982) IEEE Trans Inf Theory 28:129–137; Arthur & Vassilvitskii (2007) k-means++; Rousseeuw (1987) J Comput Appl Math 20:53–65 (silhouette); Hubert & Arabie (1985) J Classif 2:193–218 (ARI). 50 restarts by default; on the example data the partition and within-cluster sum of squares for the chosen k match scikit-learn KMeans with n_init = 100 (relative difference < 1e-6), and elbow-plot values for every k are within 1%; silhouette widths match sklearn.metrics.silhouette_score.

Data size

Up to 20,000 samples (silhouette widths are skipped above 4,000).

Need a full analysis?

Send us your data and research question and you will receive a written plan within 1 working day: analysis steps, parameter rationale, deliverables and timeline. Quoted per project.