CLUSTER ANALYSIS · BEGINNER GUIDE
Cluster analysis in statistics: a simple example
Cluster analysis groups observations by similarity. The algorithm does not know what a “good customer” or “important segment” means, so a person must choose useful features and check whether the resulting groups make sense.
Quick answer: select relevant features, scale them when their units or ranges differ, fit a clustering method, then compare group quality and usefulness across reasonable choices. Cluster labels are descriptive patterns in the input data, not facts about people or proof of cause.
What cluster analysis does
Clustering is an unsupervised learning task: there is no pre-existing answer column telling the algorithm which group each observation belongs to. A method uses a definition of similarity to assign or organize observations. Different methods define a cluster differently. K-means, for example, represents each group with a center and seeks assignments that keep observations close to their group centers. Density-based methods look for dense regions and can leave some points unassigned as noise.
Because the methods make different assumptions, there is no universal best clustering algorithm. The useful choice depends on the shape of the data, the feature types, expected noise and the purpose of the analysis. Decide what a useful grouping would mean before presenting the output as a discovery.
Worked example: six cafes
Imagine comparing six cafes using weekly customer visits and average order value:
| Cafe | Weekly visits | Average order |
|---|---|---|
| A | 20 | €8.00 |
| B | 24 | €9.00 |
| C | 27 | €8.50 |
| D | 85 | €22.00 |
| E | 90 | €24.00 |
| F | 95 | €21.00 |
On a scatter plot, A–C sit near each other and D–F sit near each other. A two-group solution could describe a lower-visit/lower-order group and a higher-visit/higher-order group. That is a description of these two chosen measurements; it does not show why the groups differ, whether the cafes are profitable or whether a business should treat them differently.
If you use k-means, you must choose the number of groups, k. Here k = 2 is a reasonable hypothesis to inspect because the plotted points separate into two visible areas. Do not select k only because a chart looks neat; compare multiple values and use domain knowledge.
Why scaling changes the result
Many clustering methods use distances. A change of 10 visits and a change of €10 are not inherently comparable. If one feature has a much larger numeric range, it can dominate distance even when the other feature matters just as much.
Standardization often transforms each feature using its training-data mean and standard deviation. It is not always the right choice: skewed values, outliers and meaningful units can affect the result. Choose a transformation based on the data and purpose, fit it consistently, and report it. If the features are categorical, ordinary Euclidean distance may be inappropriate.
When evaluating future cases, fit scaling from training data only. Computing scaling values using the full dataset before a train/test split lets information from the test portion influence the training process.
How to check whether the clusters are useful
- Inspect plots and summaries of each feature by group; look for outliers or accidental groupings driven by one variable.
- Compare several plausible values of k or method settings. A result that changes completely after a small change may be unstable.
- Use an internal score such as silhouette only as one view of separation and cohesion. A score cannot decide whether the groups matter in practice.
- Check stability by resampling or by fitting on different reasonable subsets where appropriate.
- Ask a domain expert whether a group has a useful, non-harmful interpretation before using it for decisions.
For customer or patient data, grouping can reproduce historical bias or expose sensitive patterns. Treat a cluster label as a model output, protect individual data and avoid turning exploratory groups into consequential rules without validation.
Frequently asked questions
Is cluster analysis the same as classification?
No. Classification learns from known class labels. Clustering looks for structure without those labels.
How do I know the right number of clusters?
There is no single automatic answer. Compare plausible choices, evaluate stability and separation, and decide whether the groups are meaningful for the question.
Should I always standardize the data?
No, but distance-based methods can be dominated by large-scale features. Consider units, distributions, outliers and the intended meaning before choosing a transformation.
Do clusters prove that the groups are real?
No. They are patterns under a chosen method and feature set. Different choices may give different groups, and a cluster does not explain its cause.
Sources and next steps
- scikit-learn: Clustering — method comparisons, assumptions and evaluation measures.
- scikit-learn: StandardScaler — centering and scaling features using training data statistics.
- scikit-learn: Silhouette score — one internal measure of within-cluster and between-cluster distances.