Cluster analysis sorts records into groups of similar items without being told the groups in advance, so the data itself suggests the segments. It runs as a short pipeline: prepare the data, measure similarity, group the records, pick how many groups, then check and describe them. The grouping step looks like the main event, but it is often where the least goes wrong. Most bad results come from unprepared data or a group count chosen by eye.
Step 1 Prepare Your Data Before Grouping Anything
Every column you include gets a vote in deciding who counts as similar. ID numbers or signup dates can create meaningless groups, so start with the columns tied to the question you want answered. If two columns measure the same thing twice, drop one of them.
Grouping methods compare records by distance, so a column measured in large numbers, like yearly spending in dollars, can drown out one in small numbers, like visits per month. Without rescaling, a 50-dollar difference outweighs a 20-visit difference, and the groups end up sorted almost entirely by spending.
When columns use different units, rescaling them before k-means gives clearly more accurate groups than using the raw numbers.1PubMed Central. The impact of neglecting feature scaling in k-means clustering Of the options tested, standardization (turning each column into how far a value sits from its average, in standard steps) and percentile ranking worked best.1PubMed Central. The impact of neglecting feature scaling in k-means clustering If your columns mix dollars, counts and percentages, standardize them first.
An outlier is a record far from all the others, such as one customer who spent 100 times the average. Removing outliers can make the groups more accurate.2Pattern Recognition Letters. k -means clustering with outlier removal
Before removing an extreme record, check whether it is a data entry error, such as an extra zero in a spending figure. Errors should be fixed or dropped. If the record is real, like a genuine very large buyer, decide whether you want it shaping the groups or set aside and described separately. Running the grouping with and without the outliers shows how much a few records were steering the result. Missing values need to be filled or dropped before most methods will run at all.3CrossRef API. Application of Soft-Clustering Analysis Using Expectation Maximization Algorithms on Gaussian Mixture Model
Step 2 Decide How to Measure Similarity
Every clustering method needs a rule for how far apart two records are, and the everyday default is straight-line distance. How well a distance measure works changes with the kind of data and the method used, so it should be chosen for your dataset.4INFOCOMP Journal of Computer Science. Performance Evaluation of Distance Metrics in the Clustering Algorithms
With k-means, a measure that accounts for related columns did best on data with few columns, while other measures did better on data with many columns.5PubMed Central. A Comparison Study on Similarity and Dissimilarity Measures in Clustering Continuous Data Straight-line distance treats every column as independent, so two columns that move together, such as income and spending, effectively count the same information twice. A measure that accounts for related columns adjusts for this overlap, which is why it can help on data with few columns, where the relationships are easy to estimate. Rescaling is a simpler first step: it fixes unit differences but does not remove the double counting.
Cosine similarity, which compares the direction of records rather than their size, did well on data with many columns.5PubMed Central. A Comparison Study on Similarity and Dissimilarity Measures in Clustering Continuous Data It compares patterns, not totals. Two shoppers with the same mix of categories but different budgets count as similar, whereas straight-line distance would separate them by spending level. That suits word counts in documents and purchase mixes.
A practical way to choose: start with straight-line distance on rescaled data, then try one alternative that fits your data’s shape. Compare the results with the scoring checks in Step 4, and keep the one whose groups are both well scored and make sense.
Step 3 Choose a Clustering Method and Run It Well
k-means, now over half a century old, is still one of the most popular grouping methods.6Proceedings of the VLDB Endowment. Scalable K-Means++ You choose the number of groups. It places a group center (the average point of a group) for each one, assigns every record to the nearest center, moves the centers, and repeats. It stops when assignments no longer change, which usually happens within a modest number of rounds. Stopping means the method found a stable answer, not the best possible one.
That is the weak spot. Where the centers start can change the final answer a lot, and k-means can settle on a merely decent solution rather than the best one.7Machine Learning. An empirical comparison between stochastic and deterministic centroid initialisation for K-means variations
Because each record joins its nearest center, k-means carves the space into roughly round regions of similar size. Long, curved or ring-shaped groups get cut into pieces, even when a person looking at a plot would see them as obvious single groups. Groups of very different sizes can also be split badly, as the larger group may be broken up to feed a smaller one.
Two fixes make it much more reliable. Spreading the starting centers far apart cut wrongly formed groups from about 15% to 6% on overlapping data.8Pattern Recognition. How much can k-means be improved by using better initialization and repeats? Running the method 100 times and keeping the best result cut errors to about 1%.8Pattern Recognition. How much can k-means be improved by using better initialization and repeats? So use a spread-out starting option, often called k-means++ in software, and many repeats. Even when groups are clearly separated, a poor start can still produce a wrong answer, so repeats still matter.8Pattern Recognition. How much can k-means be improved by using better initialization and repeats?
The most common mistake is running k-means once. Keep the repeat with the lowest tightness total, and use your software’s setting for the number of restarts.
When k-means doesn’t fit, there are alternatives:
- k-medoids: uses real records as group centers, which makes it less thrown off by noise and outliers.9International Journal of Soft Computing, Mathematics and Control. K-Medoids Clustering Using Partitioning Around Medoids for Performing Face Recognition
- Hierarchical clustering: builds a tree of groups by merging the closest ones step by step. Ward’s method gave the most compact, well-separated groups for round clusters.10Libyan Journal of Medical and Applied Sciences. Comparative Study of Four Methods in Hierarchical Cluster Analysis Single linkage can find long, stretched groups but chains groups together in noisy data, while average linkage is a balanced middle option.10Libyan Journal of Medical and Applied Sciences. Comparative Study of Four Methods in Hierarchical Cluster Analysis
- Density-based methods: such as DBSCAN, find groups of any shape and set aside scattered noise points.11ACM Transactions on Intelligent Systems and Technology. Significant DBSCAN+: Statistically Robust Density-based Clustering
- Gaussian mixture models: give each record a probability of belonging to each group, useful when groups overlap.3CrossRef API. Application of Soft-Clustering Analysis Using Expectation Maximization Algorithms on Gaussian Mixture Model
By data shape: numeric data with roughly round groups suits k-means. Many outliers you can’t remove point to k-medoids. If you want to see how groups nest in a small dataset, use hierarchical clustering with Ward’s method. Irregular shapes or noise points call for density-based methods, and records that plausibly belong to two groups call for mixture models.
Step 4 Pick the Number of Groups
The elbow method plots how tightly records sit around their centers for each group count and looks for the bend where adding groups stops helping much.12MetricGate. Gap Statistic vs Silhouette vs Elbow for Choosing K That total always falls as you add groups, and it reaches zero when every record is its own group, which is why you look for a bend rather than the lowest value. When groups overlap, the curve bends gradually with no clear elbow, leaving the choice to guesswork.12MetricGate. Gap Statistic vs Silhouette vs Elbow for Choosing K
The silhouette score rates how well each record fits its own group compared with the next-nearest group, and the count with the highest average score is a strong candidate.12MetricGate. Gap Statistic vs Silhouette vs Elbow for Choosing K Scores range from -1 to 1. Near 1 means records sit firmly in their own group, near 0 means they sit on the border between groups, and negative values suggest records may be in the wrong group. In a large comparison of scoring checks, the silhouette did best overall, picking the right answer more than half the time.13Pattern Recognition. An extensive comparative study of cluster validity indices The gap statistic compares your data with random scatter and is the only one of the three that can say there are no real groups.12MetricGate. Gap Statistic vs Silhouette vs Elbow for Choosing K Even the best check is right only about half the time, so treat its answer as a strong suggestion.14Jurnal Ilmiah Wahana Pendidikan. Penerapan Silhouette Coefficient, Elbow Method dan Gap Statistics untuk Penentuan Cluster Optimum dalam Pengelompokkan Provinsi di Indonesia Berdasarkan Indeks Kebahagiaan
In practice, run your method for each count from 2 to about 10, using repeated starts for each. Record the silhouette score and the tightness total for each count in a small table or plot. Then look for where the silhouette peaks and where the tightness curve bends, and see whether they agree. Prefer a count that also makes practical sense.
Sometimes the business sets the count. A marketing team may only be able to run four campaigns, and a slightly lower-scoring count can still be the right choice. Just check that it isn’t far worse than the best score.
Step 5 Check and Describe Your Clusters
Calculate the average or middle value of each column within each group to see what makes it distinct.15Displayr. How to Do Cluster Analysis: A Step-by-Step Guide Show these profiles with bar charts, line charts or radar charts.15Displayr. How to Do Cluster Analysis: A Step-by-Step Guide A group of high-spending, rarely visiting customers becomes something a team can act on.
Compare each group’s average to the overall average, because a group’s value only means something against the whole. Use the median instead of the average for columns with a few very large values, such as spending. Expressing differences in rescaled units or percent above and below overall lets you read columns in different units side by side.
A column matters if removing it makes the groups much harder to predict on records held back from the analysis.16arXiv. Cluster LOCO: Feature Importance For Interpreting Clusters Trying the analysis without each column in turn shows which ones actually define the groups.
A simple stability check: split the data randomly into two halves and cluster each separately. If similar groups appear in both, they are probably real. Groups that vanish in one half are likely noise.
Give each group a short descriptive label based on its profile, but remember that groups describe patterns, not causes. Note group sizes, since a tiny group may just be outliers, and revisit the labels when new data arrives.
What If Your Data Mixes Numbers and Categories
Most classic methods assume all columns are one type, and converting one type to the other can lose information and spoil the groups.17Neurocomputing. An improved k-prototypes algorithm for mixed numeric and categorical data17Neurocomputing. An improved k-prototypes algorithm for mixed numeric and categorical data Turning categories into numbers misleads. Coding regions as 1, 2 and 3 implies region 3 is farther from 1 than 2 is, so the method treats made-up distances as real. Splitting a category column into many 0/1 columns can also let it outweigh numeric ones.
Methods designed for mixed data, such as k-prototypes and KAMILA, handle both directly.18Journal of Probability and Statistics. Clustering Approaches for Mixed‐Type Data: A Comparative Study k-prototypes measures numeric columns with straight-line distance and categorical columns by whether the values match. A weighting setting controls how much categorical mismatches count compared with numeric distance, so it affects how the groups form. Group centers are averages for the numeric columns and the most common value for the categorical ones. For categories alone, k-modes groups records by their most common values.17Neurocomputing. An improved k-prototypes algorithm for mixed numeric and categorical data
k-prototypes and k-modes are available in common Python and R packages. Try them alongside a numeric-only version and score both with the silhouette check from Step 4.
Clustering Large or Wide Datasets
Mini-batch k-means updates centers using small random samples of records, cutting computing cost enormously compared with standard k-means.19Proceedings of the 19th international conference on World wide web. Web-scale k-means clustering For millions of rows it gives good groups in a fraction of the time. Because it learns from small samples, its groups can be slightly less tight, but for most large business datasets the difference is small next to the time saved. Run it several times with different starts, just as you would with standard k-means.
Wide data has its own problem: adding columns that carry no useful information makes groups harder to find.20Stats. Silhouette-Based Evaluation of PCA, Isomap, and t-SNE on Linear and Nonlinear Data Structures PCA, which squeezes many columns into a few summary ones, preserves groups best when patterns are roughly straight-line.20Stats. Silhouette-Based Evaluation of PCA, Isomap, and t-SNE on Linear and Nonlinear Data Structures
A practical pipeline: rescale columns first, as in Step 1. Reduce with PCA, keeping enough components to explain most variation. Cluster the reduced data and score it, then map the result back to the original columns to describe the groups.
t-SNE is meant for making pictures, not for clustering, because it distorts distances.21MCP Analytics. t-SNE vs PCA vs UMAP: Which Reveals True Clusters? Cluster in the original or PCA-reduced data, then use t-SNE only to visualize the result, and check groups on the real data before trusting them.

