Clustering Metrics

Here are some metric available for validating clustering, explanation of each one is available on sklearn. [0]

If ground truth labels are available:

  • Adjusted Rand Index
  • Mutual Information Based scores
  • Homogeneity, completeness and V-measure
  • Fowlkes-Mallows scores

If not available :

  • Silhouette Coefficient
    • Range (-1,1)
    • 1 means it is similar to data-points in each cluster
  • Calinski-Harabaz Index
  • Davies-Bouldin Index
  • Contingency Matrix

 

Calculating SSE

It is a sum of distance between each point and its cluster center.

c1

Silhouette Score

It is calculated for each point and then we take an average of it.

c2

c4
c3

          

a(i) is average distance of a point to other points in same cluster.

b(i) is minimum of above average in for point in other cluster. It given the distance to nearest cluster.

s(i) close to 1 means data point is appropriately clustered. -1 means it is very bad clustered.

Setting s(i) to 0 when cluster size is one ensures that curve is not monotonically decreasing.

 

Elbow method and Silhouette Analysis

Notebook is available at https://github.com/arcarchit/datastories/blob/master/Silhouette.ipynb

sil1
sil2

        

Rand Index

  • When cluster labels are available we can use this matrix
  • It basically checks the similarity between two cluster assignments
    • Labels can also be seen as one type of cluster assignment
    • Score basically tells us how similar to cluster assignments are
  • This works by taking pair of points
    • Out of all pairs how many pairs are agreed in both clusters mechanism
    • Agree mean both
      • They are in same cluster in both mechanism
      • They are in different cluster in both mechanism
  • The Rand index has a value between 0 and 1, with 0 indicating that the two data clustering do not agree on any pair of points and 1 indicating that the data clustering are exactly the same
rand_index

  • One drawback of Rand index is that it can given non zero value for random assignment of clusters. To mitigate that there is matrix called Adjusted Rand Index. [2]
    • It specifically does not work when no of clusters are high

Homogeneity, completeness and V-measure

To understand the difference, imagine you are sorting a basket of fruit containing Apple, Banana, and Orange into three boxes.

Here is how different sorting scenarios affect the scores:

Scenario 1: High Homogeneity, Low Completeness (The Splitter)

You put each piece of fruit into its own individual small box.

  • Result: Every box contains exactly one type of fruit (100% pure). However, your apples are scattered across multiple boxes.
  • Scores: Homogeneity = 1.0 | Completeness = Low

Scenario 2: Low Homogeneity, High Completeness (The Grouper)

You throw all the fruits—apples, bananas, and oranges—into one giant single box.

  • Result: Every single apple is in the exact same box, so no class is split up. However, the box is a messy mix of different fruits.
  • Scores: Homogeneity = Low | Completeness = 1.0

Scenario 3: Perfect Scores

You put all the apples in Box A, all the bananas in Box B, and all the oranges in Box C.

Scores: Homogeneity = 1.0 | Completeness = 1.0 

Result: Every box is perfectly pure, and no class is split across multiple boxes.


Example

 

Final Evaluation Summary

  • Homogeneity (\(0.3112\)): Low score because Cluster 0 is heavily polluted with a mix of fruits.
  • Completeness (\(0.3836\)): Also quite low because the Banana class was completely split in half across both clusters.

Reference

[0] : https://scikit-learn.org/stable/modules/clustering.html

[1] : https://github.com/anthonyng2/udemy-the-complete-machine-learning-course-with-python

[2] : https://davetang.org/muse/2017/09/21/adjusted-rand-index/