Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA002 · Metric
Calinski–Harabasz index
Compares between-cluster dispersion with within-cluster dispersion for a hard Euclidean partition.
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page.
- Choose the number of clusters Verified in Python and R
- How stable are the clusters? (bootstrap) Verified in Python and R
Do it in CodeSplash Run it on your own data, in Python or R.
- Availability
- Runs in CodeSplash
- Code example
- Complete calculation
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through discover.choose_k, discover.stability. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Compares between-cluster dispersion with within-cluster dispersion for a hard Euclidean partition.
Question / hypotheses
How large is the ratio of separation to compactness? Its ANOVA-like form does not make the selected clustering an ordinary F test.
Architecture / computational structure
A fixed scoring/calibration pipeline applied to model outputs or supplied observations; the formula and usage sections identify its operations.
Assumptions
Numerical features must have a meaningful Euclidean scale. Cluster centroids and squared distances must be appropriate; 1<k<n.
Formula / computational definition
Parameters and notation
B and W are between- and within-cluster scatter matrices; n is sample count and k cluster count. Feature scaling and k are analysis choices, not learned parameters of the index.
Fitting, fine-tuning, and adaptation
There is no model fine-tuning step for this evaluation procedure. Freeze the evaluated systems and evaluator before the final test. Select evaluation settings on development data; if a learned evaluator or calibration model is adapted, use separate fitting data, version it, and reassess its validity.
How to use and calibrate
Calculate on a common feature representation, compare candidate partitions, then corroborate with stability and domain utility. Plot CH versus k with the clustering algorithm and initialization fixed.
Example application
Choose candidate segmentation resolutions for standardized sensor summaries.
Interpretation / pitfalls
Watch out
Higher is better only relative to the same data geometry. The index prefers convex, centroid-friendly clusters; its large value supplies neither a p-value nor a guarantee of recovery.
Python and R code examples
Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.
Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs numpy, sklearn
import numpy as np
from sklearn.metrics import calinski_harabasz_score
X=np.array([[0.,0.],[0.,1.],[1.,0.],[8.,8.],[8.,9.],[9.,8.]])
print(calinski_harabasz_score(X,[0,0,0,1,1,1]))
Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.
X <- rbind(c(0,0),c(0,1),c(1,0),c(8,8),c(8,9),c(9,8)); g <- c(1,1,1,2,2,2)
W <- sum(vapply(split(seq_len(nrow(X)),g),function(i) sum(scale(X[i,,drop=FALSE],scale=FALSE)^2),0.0))
T <- sum(scale(X,scale=FALSE)^2); k <- length(unique(g)); n <- nrow(X)
print(((T-W)/(k-1))/(W/(n-k)))
Sources
- Source 1scikit-learn.org
From the CodeSplash reference, entry EVA002.