What is the Within-Cluster Sum of Squares Score?

K-Means plot with compact clusters and marked centroids
Title: K-Means plot with compact clusters and marked centroids
Source: AIML.com Research

Introduction

The Within-Cluster Sum of Squares (WCSS) is a metric used in clustering, especially K-means clustering, to measure how compact the clusters are. It represents the total squared distance between each data point and the centroid of the cluster it belongs to. In simple terms, WCSS tells you how tightly grouped your data points are within each cluster. A lower WCSS indicates more compact, tighter clusters.

Mathematically, it is defined as:

\[ \text{WCSS} = \sum_{k=1}^{K} \sum_{x_i \in C_k} \lVert x_i – \mu_k \rVert^2 \]

Where:

  • $K$ is the number of clusters
  • $C_k$ is the set of points in cluster $k$
  • $x_i$ is a data point
  • $\mu_k $​ is the centroid of cluster $k$

Example

Imagine you are clustering customers based on their annual income and spending score. 

Suppose you try two clusterings:

  • $K=2$: Customers are split into two broad groups
  • $K=5$: Customers are divided into 5 more specific, fine-grained groups.

When you calculate WCSS:

  • With $K=2$, clusters are large and spread out → higher $WCSS$
  • With $K=5$, clusters are smaller and more focused → lower $WCSS$

As you increase the number of clusters, WCSS will always decrease because each cluster contains fewer points, making them closer to their centroids (refer pic below). This behavior is why WCSS is often used in the Elbow Method, where you look for a point at which adding more clusters yields diminishing improvements.

K-Means Clustering with K=2 vs K=5
Title: K-Means Clustering with K=2 vs K=5.
Source: AIML.com Research

When to Use WCSS

WCSS is best used when:

  • You are working with K-means or centroid-based clustering.
  • You want to evaluate cluster compactness.
  • You need a heuristic for choosing the number of clusters (e.g., the Elbow Method).
  • Your data is numeric and distances are meaningful (e.g., Euclidean distance).

Limitations of WCSS

Despite its usefulness, WCSS has several limitations:

  • Always decreases with more clusters
    This makes it impossible to directly compare models with different $K$ values without additional heuristics like the elbow plot.

  • Sensitive to scale
    Features with larger numeric ranges dominate the distance calculations, so proper feature scaling is essential.

  • Assumes spherical clusters
    WCSS works best when clusters are roughly circular and equally sized. It performs poorly for elongated or irregularly shaped clusters.

  • Not comparable across datasets
    The absolute WCSS value depends on dataset size and scale, making it hard to interpret in isolation.

Summary

WCSS measures how tightly grouped clusters are by summing the squared distances of points from their cluster centroids. It is simple, intuitive, and widely used in K-means clustering, particularly for selecting the number of clusters. However, it should not be used alone and works best when paired with other methods like silhouette score or domain knowledge.

Video Explanations

  • This video “Machine Intelligence – Lecture 7 (Clustering, k-means, SOM)” by Kimia Lab presents a lecture on clustering taught at University of Waterloo. Starting at 23:33, the video introduces the WCSS equation and how it is used to evaluate K-means clustering performance (Runtime: 9 mins)
YouTube video
Machine Intelligence – Lecture 7 (Clustering, k-means, SOM) at University of Waterloo by Kimia Lab
  • This video “Clustering” by MIT OpenCourseWare provides a detailed lecture on the clustering algorithm, as well as demos of real world usage examples. (Runtime: 51 mins)
YouTube video
Clustering by MIT OpenCourseWare

Author

  • MS in Computer Science at Columbia University

    Machine Learning Researcher

Help us improve this post by suggesting in comments below:

– modifications to the text, and infographics
– video resources that offer clear explanations for this question
– code snippets and case studies relevant to this concept
– online blogs, and research publications that are a “must read” on this topic

Leave the first comment

Partner Ad
Find out all the ways that you can
Contribute