induwara.lk
induwara.lkAI · Clustering metrics

Calinski–Harabasz Index Calculator

Paste your data points and cluster labels to get the Calinski–Harabasz index (variance ratio criterion), the BGSS/WGSS breakdown, per-cluster centroids, and the (N−k)/(k−1) scaling. Matches scikit-learn calinski_harabasz_score. No signup, nothing uploaded.

By Induwara AshinsanaUpdated Jul 12, 2026
Calinski–Harabasz index calculator

One point per line. Coordinates separated by commas or spaces.

One label per point, same order. Numbers or names (e.g. 0, 0, 1).

Decimals (working panel)
Examples
Calinski–Harabasz index
65.33
Higher is better · no upper bound

The Calinski–Harabasz index (variance ratio criterion) rewards clusters that are dense and well separated. There is no fixed “good” value — it grows with the number of points, so it is only meaningful when you compare different values of k on the same dataset. The higher of two scores marks the better clustering.

Points (N)
6
Clusters (k)
3
Dimensions
2
Scale (N−k)/(k−1)
1.5

Dispersion breakdown

BGSS (between)
261.3333
WGSS (within)
6.0000
Ratio BGSS / WGSS
43.5556
CH = (BGSS / WGSS) × ((N − k)/(k − 1)) = 43.5556 × 1.5000 = 65.33
Reconciliation: BGSS + WGSS = 261.3333 + 6.0000 = 267.3333 · TSS = 267.3333 ✓ matches

Cross-check. Between-cluster dispersion summed directly is 261.3333; recovered independently from the total scatter as TSS − WGSS it is 261.3333. The identity BGSS + WGSS = TSS holds, as it must.

Per-cluster working

ClusterSize n_qCentroid c_qBetween n_q‖c_q−c‖²Within Σ‖x−c_q‖²
02(1.0000, 0.0000)76.88892.0000
12(11.0000, 0.0000)76.88892.0000
22(6.0000, 11.0000)107.55562.0000
Totals261.33336.0000

Method: BGSS = Σ n_q ‖c_q − c‖² (between), WGSS = Σ ‖x − c_q‖² (within), CH = (BGSS / WGSS) · ((N − k)/(k − 1)); squared Euclidean throughout. Matches scikit-learn calinski_harabasz_score. Sources: scikit-learn docs, Caliński & Harabasz (1974). Nothing leaves this page.

How it works

The Calinski–Harabasz index — also called the variance ratio criterion — measures how well a set of points is clustered by comparing the spread between clusters against the spread within them. It needs no ground-truth labels, which makes it an internal validity index: the standard way to judge a k-means, hierarchical, or DBSCAN result and to compare different choices of k. It was introduced by Caliński and Harabasz in 1974 and is what scikit-learn returns from calinski_harabasz_score.

For N points partitioned into k clusters, the tool computes four things, all with squared Euclidean distance:

  1. Centroids. The overall centroid c = (1/N)·Σ xᵢ (mean of all points) and each cluster centroid c_q = (1/n_q)·Σ x.
  2. BGSS — between-cluster dispersion. The trace of the between-group scatter: BGSS = Σ_q n_q · ‖c_q − c‖². Large when cluster centroids are far apart — clusters are well separated.
  3. WGSS — within-cluster dispersion. The trace of the within-group scatter: WGSS = Σ_q Σ_{x∈C_q} ‖x − c_q‖². Small when points sit close to their own centroid — clusters are compact.
  4. The index. CH = (BGSS / WGSS) · ((N − k) / (k − 1)). The ratio rewards separated, compact clusters; the (N − k)/(k − 1) factor corrects for the number of clusters so different k are comparable. Higher is better, with no fixed upper bound.

The index is defined only for 1 < k < N; scikit-learn raises an error otherwise, and this tool shows a clear inline message. As a credibility check it also computes the total scatter TSS = Σ ‖xᵢ − c‖² independently and confirms the identity BGSS + WGSS = TSS. If WGSS is exactly zero (perfectly compact clusters) the ratio is infinite; matching scikit-learn, the tool reports 1.0 and flags the convention. The whole computation is O(N·d) in the number of points and dimensions, so it stays instant in the browser for the few-thousand-point inputs this tool accepts.

Worked examples

Well-separated clusters (1-D) — points 1, 2, 10, 11; labels 0, 0, 1, 1

  1. Overall centroid c = (1+2+10+11)/4 = 6
  2. Cluster centroids: c_A = 1.5, c_B = 10.5; n_A = n_B = 2
  3. BGSS = 2·(1.5−6)² + 2·(10.5−6)² = 2·20.25 + 2·20.25 = 81
  4. WGSS = (1−1.5)²+(2−1.5)² + (10−10.5)²+(11−10.5)² = 0.25·4 = 1
  5. CH = (81 / 1) × ((4−2)/(2−1)) = 81 × 2 = 162.0
  6. Cross-check: TSS = 25+16+16+25 = 82 = BGSS(81) + WGSS(1) ✓

Three clusters (2-D) — C1={(0,0),(2,0)}, C2={(10,0),(12,0)}, C3={(6,10),(6,12)}

  1. Overall centroid c = (6, 3.6667)
  2. Centroids: c₁=(1,0), c₂=(11,0), c₃=(6,11); each n_q = 2
  3. BGSS = 2·(25+13.4444) + 2·(25+13.4444) + 2·(0+53.7778) = 261.3333
  4. WGSS = 2 + 2 + 2 = 6 (each pair sits 1 unit either side of its centroid)
  5. CH = (261.3333 / 6) × ((6−3)/(3−1)) = 43.5556 × 1.5 = 65.33
  6. Cross-check: TSS = 267.3333 = BGSS + WGSS ✓

Perfectly compact clusters (WGSS = 0) — (0,0),(0,0) vs (5,5),(5,5); labels 0, 0, 1, 1

  1. Both points in each cluster are identical, so every c_q equals its members
  2. WGSS = 0 (nothing spreads within a cluster)
  3. BGSS/WGSS is mathematically infinite
  4. scikit-learn returns 1.0 by convention when WGSS = 0
  5. This tool reports CH = 1.0 and flags the convention with a banner

Frequently asked questions

Sources & references

The formulas on this page were last cross-checked against these sources on 2026-07-12. The Calinski–Harabasz index is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled against scikit-learn.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.