Cluster Analysis: Methods, Steps and a Worked K-Means Example
Cluster analysis groups items so that items in the same group are more alike than items in other groups. Nobody tells the method what the groups should be. It finds them in the data. That makes it useful for customer segmentation, defect pattern analysis, supplier grouping and many other problems.
This guide explains the main clustering methods, how to do clustering step by step, how to choose the number of clusters, and how to read the results. It includes a worked k-means example with the figures checked, and a section on where cluster analysis fits in Lean Six Sigma.
What Is Cluster Analysis?
Cluster analysis is an unsupervised method. You give it a set of items (customers, parts, orders, sites) and a few measured variables for each item. The method measures how close each item is to the others and forms groups of close items.
It differs from classification. In classification, the groups already exist and you train a model to sort new items into them. In clustering, you discover the groups.
| Question | Cluster analysis | Classification |
|---|---|---|
| Are the groups known in advance? | No | Yes |
| Type of method | Unsupervised | Supervised |
| Typical output | New segments to describe and name | A label for each new item |
| Example | Find natural customer segments | Predict whether an order will be late |
Types of Clustering Methods
| Method | How it works | Strengths | Watch out for |
|---|---|---|---|
| K-means | Places k centres, assigns each item to the nearest centre, moves centres to the mean of their items, and repeats | Fast, simple, works on large data sets | You must choose k. Sensitive to outliers and to scale. Assumes round clusters |
| Hierarchical (agglomerative) | Starts with every item alone and merges the closest pair again and again, shown as a dendrogram | No need to fix k first. The dendrogram is easy to explain | Slow on very large data sets. Results depend on the linkage rule |
| DBSCAN (density based) | Groups items in dense areas and labels isolated items as noise | Finds odd shapes and flags outliers | Needs two tuning settings. Struggles when density varies |
| Gaussian mixture models | Fits several overlapping normal distributions and gives each item a probability of belonging to each | Soft membership, handles oval clusters | More complex to explain and tune |
| K-modes and k-prototypes | Versions of k-means for categorical or mixed data | Works with categories such as region or product type | Less widely available in basic tools |
How to Do Clustering: 7 Steps
Step 1: Define the objective
State what decision the clusters will support. For example, "Design three service levels for our customers" or "Find groups of defects with similar causes". The objective decides which variables matter.
Step 2: Choose and prepare the variables
Pick a small number of variables that relate to the objective. Remove duplicates, fix errors and decide how to handle missing values. Avoid using two variables that measure almost the same thing, because that gives the idea double weight.
Step 3: Standardise the variables
Variables on large scales (such as dollars) will dominate variables on small scales (such as years) unless you standardise. The usual method is the z-score: z = (value − mean) ÷ standard deviation. After this, every variable has a mean of 0 and a standard deviation of 1.
Step 4: Choose a distance measure and method
Euclidean distance (straight-line distance) is the default for numeric data. K-means is a good first choice for numeric data. Use hierarchical clustering when the data set is small and you want a dendrogram.
Step 5: Choose the number of clusters
Use more than one guide:
- Elbow method: plot the within-cluster sum of squares (WCSS) for k = 1, 2, 3 and so on. Look for the point where the curve bends and extra clusters add little.
- Silhouette score: ranges from −1 to 1. Higher means items sit well inside their own cluster and away from others.
- Dendrogram: for hierarchical clustering, look for a long vertical gap where a horizontal cut gives clear groups.
- Business sense: the clusters must be few enough and different enough to act on.
Step 6: Run the analysis
Run k-means several times from different random starts and keep the best solution. Most software does this for you.
Step 7: Profile, name and test the clusters
Calculate the average of each variable for each cluster, in the original units. Give each cluster a plain name. Then check with people who know the process whether the groups make sense and whether they would act differently for each group.
Worked Example: K-Means Customer Segmentation
Illustrative example with made-up data. A retailer wants to design service levels. It has four variables for ten customers.
| Customer | Annual spend ($) | Visits per year | Tenure (years) | Product categories |
|---|---|---|---|---|
| 1 | 1,200 | 15 | 3 | 4 |
| 2 | 3,500 | 40 | 5 | 6 |
| 3 | 800 | 8 | 1 | 2 |
| 4 | 5,200 | 52 | 7 | 8 |
| 5 | 1,100 | 12 | 2 | 3 |
| 6 | 4,800 | 48 | 6 | 7 |
| 7 | 600 | 6 | 1 | 2 |
| 8 | 3,200 | 35 | 4 | 5 |
| 9 | 900 | 10 | 2 | 3 |
| 10 | 5,000 | 50 | 8 | 8 |
Standardise
Annual spend has a mean of $2,630 and a sample standard deviation of about $1,911. Customer 4's z-score for spend is (5,200 − 2,630) ÷ 1,911 = 1.34. Customer 7's is (600 − 2,630) ÷ 1,911 = −1.06. The same is done for visits (mean 27.6, SD 19.1), tenure (mean 3.9, SD 2.51) and categories (mean 4.8, SD 2.35).
Choose k
| Number of clusters (k) | WCSS | Average silhouette |
|---|---|---|
| 1 | 36.0 | n/a |
| 2 | 5.46 | 0.69 |
| 3 | 1.84 | 0.66 |
| 4 | 0.98 | 0.59 |
| 5 | 0.59 | 0.48 |
WCSS drops sharply from k = 1 to k = 2, and again to k = 3, then levels off. The silhouette is highest at k = 2 and still strong at k = 3. Both are valid. The team picks k = 3 because it wants three service levels and the third cluster is clearly different.
Results
| Cluster | Customers | Avg spend | Avg visits | Avg tenure | Avg categories |
|---|---|---|---|---|---|
| A: Loyal high spenders | 4, 6, 10 | $5,000 | 50 | 7.0 years | 7.7 |
| B: Growing regulars | 2, 8 | $3,350 | 37.5 | 4.5 years | 5.5 |
| C: Occasional buyers | 1, 3, 5, 7, 9 | $920 | 10.2 | 1.8 years | 2.8 |
Check one figure: cluster C spend = (1,200 + 800 + 1,100 + 600 + 900) ÷ 5 = 4,600 ÷ 5 = $920.
Act on the clusters
- Cluster A: protect the relationship with a named contact and priority service.
- Cluster B: cross-sell into more categories to move them towards cluster A.
- Cluster C: make buying easy and low cost to serve, such as self-service ordering.
Common Problems and Fixes
| Problem | Fix |
|---|---|
| One variable dominates the clusters | Standardise all variables first |
| Outliers pull k-means centres | Investigate them, cap extreme values, or use DBSCAN or k-medoids |
| Categorical data such as region | Use k-modes, k-prototypes or Gower distance |
| Different runs give different clusters | Use many random starts and check the solution is stable |
| Clusters are hard to explain | Use fewer, more meaningful variables and profile clusters in original units |
Tools for Cluster Analysis
- Minitab: Stat > Multivariate > Cluster Observations (hierarchical) or Cluster K-Means.
- Python: scikit-learn provides KMeans, AgglomerativeClustering, DBSCAN and silhouette_score.
- R: kmeans() and hclust() in base R.
- Excel: possible for small data sets with Solver or add-ins, but slow to repeat.
Cluster Analysis in Lean Six Sigma
Cluster analysis is an Analyse phase tool. It helps a team see that one process is really several processes, each needing its own fix. Examples include:
- grouping defects by temperature, humidity and material batch to find conditions that produce scrap
- splitting customer orders into simple and complex types before setting cycle time targets
- grouping sites or suppliers with similar performance to share good practice
It works well alongside data stratification, which splits data by known factors, and customer segmentation. If a histogram of your process looks like two humps, read about bimodal distributions: clustering can help explain where the two groups come from.
Multivariate tools such as cluster analysis are covered in the Lean Six Sigma Black Belt online training. The Green Belt online training covers the core data analysis skills that come first.
Frequently asked questions
What is cluster analysis?
Cluster analysis groups items so that those in the same group are more similar to each other than to items in other groups, without needing predefined labels.
How do you do clustering?
Choose the variables, standardise them, pick a method such as k-means or hierarchical clustering, decide the number of clusters, run the analysis, then describe and name each cluster.
How do you choose the number of clusters?
Use the elbow method on a plot of within-cluster sum of squares, silhouette scores, or a dendrogram for hierarchical clustering. Then check that the clusters make practical sense.
What is the difference between k-means and hierarchical clustering?
K-means needs you to choose the number of clusters first and works well on large data sets. Hierarchical clustering builds a tree of merges, so you can choose the number of clusters afterwards, but it is slower on large data.
Why do you standardise data before clustering?
Clustering uses distance. Without standardising, a variable measured in thousands of dollars would outweigh a variable measured in years, and the clusters would reflect only that one variable.
Is cluster analysis supervised or unsupervised?
It is unsupervised. The groups are not known in advance. The method discovers them from the data.
What is a practical example?
Grouping customers by spend, visits, tenure and range of products bought to design three service levels, as in the worked example above.