Multivariate & ML · Clustering

k-Means Clustering

Partition observations into k clusters by minimizing within-cluster distance, with centroids, inertia, and silhouette score.

In the menus Multivariate & ML › Clustering › k-Means Clustering

Also searched as k means kmeans cluster clustering segmentation group similar rows

When to use it

Find natural groupings in numeric data when you don't have labels: customer segments, specimen types, regions of behavior.

When not to: Clusters are expected to be elongated, irregularly shaped, or very different in size (k-means' spherical-cluster assumption will distort the result), you do not want to commit to a specific k in advance (hierarchical clustering lets you inspect the tree before cutting), or the data may have NO real cluster structure at all: k-means will still confidently produce k groups regardless, and only a low silhouette score (or a formal check like the gap statistic, which this function does not compute) would reveal that.

Step by step

  1. Open it from the menu

    Click Multivariate & ML in the menu bar; under Clustering choose k-Means Clustering.

  2. Fill in the form

    Choose the columns: Columns to group rows by. The form lists only columns whose type fits each field.

  3. Check the options

    The options start at their defaults: Number of clusters (k), Standardize, Restarts (n_init), Random seed. Change one only when your question needs it.

  4. Run the analysis

    Press Run analysis. The Result Card opens on its Results tab.

What to choose in the form

Fields of the k-Means Clustering form
Columns to group rows by Variables requiredOne numeric column. One or more continuous variables to cluster on.
Number of clusters (k)How many clusters to form. Default: 3.
StandardizeStandardize each variable to mean 0, SD 1 before clustering so no variable dominates by scale. Default: on.
Restarts (n_init)Number of random initializations; the best (lowest-inertia) run is kept. Default: 10.
Random seedSeed for reproducible cluster assignments. Default: 42.

How to read the card

The Results tab starts with what to know first (rows left out, checks that did not pass), then the interpretation in words and the Key Results; charts and assumption checks follow further down. Learn More explains the method in plain words. Read a Result Card covers all four tabs.

What it assumes

Independence of observations

If it does not hold: k-means treats every row as an independent point in space; clustering rows that are actually repeated measurements of the same unit, or otherwise dependent, can create spurious 'clusters' that just reflect the grouping structure rather than genuine subpopulations.

How to check: Not checked by KernelStats.

A worked example

k-means (k=3, standardized, 10 restarts, seed 42) on four penguin body measurements across 342 birds.

Result: Inertia = 379.4, silhouette = 0.45 ('weak' on Rousseeuw's bands), with cluster sizes of 87, 123 and 132; the 123 matches the Gentoo count, while the other two clusters cut across the 151 Adelie and 68 Chinstrap.

A silhouette of 0.45 says the three groups overlap substantially: one cluster (Gentoo) is well separated, but the split of the remaining birds is not a clean natural break in these four measurements. Checking the clusters against species labels is external corroboration the silhouette cannot provide, and here it shows k-means does not recover all three species.

From the Statistics Library.

The code tabs

Code gives this analysis as Python, R and MATLAB code (and SAS where the tab offers it), reading the data the way KernelStats did. Export sends the card to a report or to slides. See The Code tab.

Understand the statistics

Ask Oobi

Type one of these into Ask Oobi beside your data:

  • Do penguins fall into distinct groups based on their body measurements?
  • Explain the k-Means clustering in plain words.
  • What does outliers mean?

Last reviewed November 16, 2026.

Report an unclear step