Machine learning & feedback
k-means clustering: why feature scaling matters
Which customers are similar? The answer also depends on how similarity is measured. Group the same synthetic customers by order count and monthly revenue, and explore the effect of scaling.
The short answer
k-means groups observations around nearby group means. Its distances depend on feature scales. Standardisation can reduce the dominance of large numerical values, but cannot replace a meaningful choice of features and weights.
Try the free interactive calculatorFree · in your browser · no sign-up
At a glance
- k-means forms groups using the numerical distances you specify.
- Euros and thousands of euros can produce different groups without scaling.
- Groups are model proposals, not established customer types or causal explanations.
When are two customers similar?
Imagine 90 customers described by two features: monthly order count and monthly revenue in euros. One customer orders twelve times and generates €1,800, another orders 52 times and generates €2,000. A third places 32 orders and generates €6,500. Which customers belong together? Even this simple question requires a definition of closeness and a purpose for forming groups.
The learning example generates synthetic points around three different means. The displayed groups are then calculated afresh by k-means; the original generating group is not used as a target. There are no real customer records, names or assessments of individuals. The construction provides a controlled setting for changing units and scaling.
How k-means forms groups
The algorithm starts with selected observations as centres. It assigns each point to the nearest centre, then calculates a new mean for each group. Assignment and averaging repeat until the centres stop moving or the iteration limit is reached. The official description explains this Lloyd procedure and its objective based on squared distances (scikit-learn developers 2026).
A small numerical example makes the centre concrete. Points and have centre . Points and have centre . Each point is one unit from its centre, so the sum of the four squared distances is four. That is the inertia for this assignment.
For a given group count, the application always starts from the same observations. This isolates the effect of changing scaling instead of simultaneously introducing different initial points. It does not guarantee a global optimum. K-means can reach different local solutions from different starts. A practical analysis would include multiple initialisations and an examination of stability.
Why euros can dominate distance
Without scaling, squared Euclidean distance adds the squared differences in each feature. A €1,000 revenue difference contributes one million, while a difference of 40 orders contributes only 1,600. Revenue can therefore dominate grouping even though “1,000” partly reflects the chosen currency unit. Features are combined mathematically without automatically receiving meaningful business weights.
Changing euros to thousands of euros turns that revenue difference into one, whose squared contribution is also one. Order count can now dominate. Nothing about the customers has changed; only the way revenue is expressed is different. The sensitivity of distance-based methods to feature scales is a central reason to make preprocessing choices deliberately (scikit-learn developers 2026).
Experiment with group count and scaling
k-means clustering – interactive calculator
90 synthetic customers are grouped by monthly order count and revenue. Switch between euros and thousands of euros, toggle standardisation and compare two to five groups.
First turn standardisation off and switch the revenue unit. Compare assignments, centres and group sizes. The chart deliberately keeps its original labels in euros and orders; only the algorithm’s internal distances use the selected unit. Changes are therefore not hidden by stretching the drawing differently.
Next enable standardisation. Each feature has its mean subtracted and is divided by its standard deviation. Euros and thousands of euros then yield the same standardised values apart from rounding. Assignments should therefore remain unchanged. Finally, change the number of groups. More groups permit smaller subsets, but do not establish which subsets are operationally useful.
What a segmentation does not establish
K-means is particularly suited to compact groups in the chosen distance space. Long curved structures, strong outliers and very different spreads can cause problems. Standardisation does not remove these modelling limitations. It may also give more weight to a noisy feature that would have been better excluded on substantive grounds.
A useful segmentation therefore needs a specific purpose. Is the aim to simplify a service process, understand product usage or organise a portfolio? Check whether groups remain stable over time and whether different actions actually make sense for them. Labels such as “valuable” or “risky” do not follow from the algorithm. They require separate definitions, evidence and appropriate judgement.
Before adopting a segment, compare it with a simple existing rule and describe what would change in practice. If nobody can name a different action, an attractive chart may have little operational value. The regression and overfitting article adds another reason to test convincing patterns independently rather than equating a good fit with useful knowledge.
Frequently asked questions
Must features always be standardised before k-means?
Not always. Standardisation equalises variance scales, but may change meaningful business weights. The key question is which distances make sense for the task.
Does k-means find the right number of groups automatically?
No. The number of groups is supplied in advance. More groups usually reduce fitting error, but do not establish a more useful segmentation.
Sources and further reading
- Onlinescikit-learn developers (2026): Clustering: K-means.
- Onlinescikit-learn developers (2026): Importance of Feature Scaling.
Content last reviewed on 14 November 2026. Please let us know about any errors: impressum@nyxai.com.