Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Calinski-Harabasz index

scikit-learn and back-of-envelop calculations

Example #1

CH score calculated using scikit-learn: 0.5
CH score calculated semi-automatically: 0.5

Manual back-of-envelop calculation

n_clusters = 2

n_samples = 4

overall_mean = [4, 5]

Cluster #0: X = [[1, 2], [5, 6]], y = 0, centroid = [3, 4]

        ssb = 2 * (Euclidean between [3, 4] and [4, 5])^2 

            = 4

        ssw = (Euclidean between [1, 2] and [3, 4])^2 +

              (Euclidean between [5, 6] and [3, 4])^2

            = 16

Cluster #1: X = [[3, 4], [7, 8]], y = 1, centroid = [5, 6]

        ssb = 2 * (Euclidean between [5, 6] and [4, 5])^2

            = 4

        ssw = (Euclidean between [3, 4] and [5, 6])^2 +  

              (Euclidean between [7, 8] and [5, 6])^2  

            = 16

ssb = 4 + 4 = 8

ssw = 16 + 16 = 32

ch = 8 / 32 * (4 - 2) / (2 - 1) = 0.5

Example #2

CH score calculated using scikit-learn: 0.3
CH score calculated semi-automatically: 0.3
<Figure size 720x720 with 4 Axes>

Example #3

<Figure size 1080x1080 with 9 Axes>