Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 59

Assessing Cluster Quality and Number

Recommended resources

Introduction

In our previous lesson, we successfully built a K-Means clustering model using the K-Centroids Cluster Analysis tool. We walked through its configuration, but we had to make a crucial assumption: we had to manually specify the number of clusters, K. This raises a critical question: how do we know if three clusters are better than four, or five? Choosing the right number is fundamental to creating meaningful and reliable segments.

Today, we'll answer that question. This lesson focuses on how to evaluate cluster quality and determine an appropriate number of clusters. We will break this down into a two-step process:

  1. First, you'll learn how to use the K-Centroids Diagnostics tool to statistically compare different values for K and find the optimal number for your data.
  2. Second, once we've chosen K, you'll learn how to interpret the summary report from the K-Centroids Cluster Analysis tool to assess the quality of your final clusters, ensuring they are both cohesive and distinct.

By the end of this lesson, you'll be able to move beyond guesswork and confidently justify your choice of clusters based on robust statistical evidence.


Part 1: Finding the Optimal Number of Clusters (K)

The number of clusters you choose directly impacts the quality of your insights. Too few, and you might group distinct customer types together. Too many, and you might over-segment, creating tiny, meaningless groups that are hard to act upon. Alteryx provides a specific tool to help navigate this trade-off: the K-Centroids Diagnostics tool.

Alteryx K-Centroids Diagnostics Tool
The K-Centroids Diagnostics tool is designed to help you assess the appropriate number of clusters for your data before you build your final model.

This tool works by testing a range of cluster numbers (e.g., from 2 to 6) and providing metrics that measure the "goodness" of each potential solution. To do this reliably, it uses a technique called bootstrapping, where it runs the clustering algorithm on many different random samples of your data for each value of K. This ensures the results are stable and not just a fluke.

The tool's output includes two key statistical scores that we will use to make our decision: the Calinski-Harabasz (CH) Index and the Adjusted Rand Index (ARI).

To understand these metrics, let's turn to a helpful article.

Interpreting Predictive Grouping Tools: K-Centroids Diagnostics

This article from The Information Lab provides clear definitions for the K-Centroids Diagnostics tool and the two key indices it produces. As you read, focus on what each index measures and whether a higher or lower score is better.

Read the sections titled 'K- Centroids Diagnostics Tool', 'Adjusted Rand Index', and 'Calinski – Harabasz Index'.

Let's summarize and visualize what you've just read.

Calinski-Harabasz (CH) Index

The CH index is a ratio that captures the core idea of good clustering:

  • High "between-cluster" variance: The clusters should be far apart from each other.
  • Low "within-cluster" variance: The data points within each cluster should be close together (compact).

CH Index = (Between-Cluster Variance) / (Within-Cluster Variance)

Therefore, a higher CH Index is better, indicating clusters that are both compact and well-separated.

K-Means Clustering Scatter Plot
This plot illustrates good clustering. The clusters (red, green, blue) are compact (low within-cluster variance) and clearly separated from one another (high between-cluster variance), which would result in a high CH Index.

Adjusted Rand Index (ARI)

The ARI measures the stability and similarity of clustering solutions across the different bootstrap samples. It answers the question: "If I take a different random sample of my data, do I get roughly the same clusters?"

  • An ARI score near 1 suggests very similar, stable clusters.
  • An ARI score near 0 suggests the clustering is no better than random chance.

A higher ARI is better, indicating that the clusters found are consistent and likely represent a real pattern in the data.

Interpreting the Diagnostic Report

The report from the Diagnostics tool doesn't give a single score but a statistical summary (min, max, quartiles, mean). Why? This is a direct result of the bootstrapping process.

Interpreting Predictive Grouping Tools: K-Centroids Diagnostics

Let's return to the same article to understand how to interpret the summary table and use it to make a decision.

Read the section titled 'Why are these split into quartiles, minimum and maximum?'. Focus on the strategy for selecting a number of clusters based on these ranges (e.g., looking at the mean or median score).

How to Decide on K:

  1. Look for the "Elbow": Scan the Mean_Calinski_Harabasz column. You are looking for the number of clusters (K) that gives the highest score. Often, the score will increase sharply and then level off or decrease. This "elbow" point is a strong candidate for the optimal K.
  2. Check for Stability: For the K you identified, look at the Mean_Adj_Rand_Index. This score should be reasonably high (e.g., above 0.2, ideally higher). A high CH index with a very low ARI might suggest an unstable solution.
  3. Consider the Range: Look at the Median scores as well as the Q1 (first quartile) and Q3 (third quartile). A tight range between Q1 and Q3 for a given K indicates a more consistent result across samples, which increases confidence in that choice.

Ultimately, this is a diagnostic step. You might find that K=3 and K=4 both produce good statistical results. The final choice can then also be influenced by business context, which we will cover in the next lesson.


Part 2: Evaluating the Final Model's Quality

Once you've used the Diagnostics tool to choose an optimal K (let's say you chose K=3), you re-run the K-Centroids Cluster Analysis tool with Number of clusters set to 3.

Now, we need to evaluate the quality of this final model. For this, we look at the 'R' (Report) output. The report contains a "Cluster Information" table with several useful metrics that describe the size, cohesion, and separation of your final clusters.

The key metrics to examine are:

  • Size: The number of data points in each cluster.
  • Ave. Distance: The average Euclidean distance of points from their cluster's center (centroid).
  • Max. Distance: The distance of the single furthest point from its cluster's centroid.
  • Separation: The distance from one cluster to the center of the next closest cluster.

A detailed, practical explanation of these metrics is often found where users share their hands-on experience.

Tool Mastery | K-Centroids Cluster Analysis

A fantastic explanation of these metrics can be found in a user comment on the Alteryx Community's 'Tool Mastery' page. This user breaks down exactly what 'Ave Distance', 'Max Distance', and 'Separation' mean and how to interpret them.

This article was used in the previous lesson. Scroll down to the comments section and find the detailed post by the user 'h_kee' dated 10-11-2018. Read this comment carefully to understand how each metric is calculated and what it tells you about your clusters.

Synthesizing the Evaluation Metrics

Based on that reading, here is how to interpret the metrics in the cluster report to judge your model's quality:

Metric What it Measures How to Interpret It
Size Number of records per cluster Check for balance. Are the clusters reasonably sized? A cluster with only a handful of records might be a group of outliers, not a meaningful segment.
Ave. Distance Cohesion (tightness) Lower is better. A small average distance means the points within the cluster are very similar to each other and tightly packed around the center.
Max. Distance Outliers within a cluster A Max. Distance that is much larger than the Ave. Distance might indicate the presence of outliers within that cluster.
Separation Distinction (separation) Higher is better. A large separation value means your cluster is far away from its nearest neighbor, indicating it is distinct and not easily confused with other clusters.

A high-quality clustering solution will have clusters that are both cohesive (low Ave. Distance) and well-separated (high Separation). By examining these metrics, you can confirm that the K you chose has produced meaningful, distinct, and internally consistent groups.


Conclusion

In this lesson, you have moved from arbitrarily picking a number of clusters to making an informed, data-driven decision. You now have a systematic process for ensuring your segmentation is statistically sound.

Key Takeaways:

  • Use the K-Centroids Diagnostics tool as the first step to determine the optimal number of clusters (K).
  • Interpret the Calinski-Harabasz Index (higher is better for separation) and the Adjusted Rand Index (higher is better for stability) to guide your choice of K.
  • After building your final model with the chosen K, evaluate its quality using the Cluster Information table in the report output.
  • A good model has clusters that are cohesive (low Ave. Distance) and well-separated (high Separation).

Preview of the Next Lesson:
We have now identified a statistically valid set of clusters. But what do these clusters mean? Who are the people in Cluster 1 versus Cluster 2? In our next lesson, "Interpret cluster profiles to create business-relevant segment personas," we will dive into the Cluster Centroids table to understand the characteristics of each cluster and translate our data science results into actionable business insights.