# Calinski Harabasz Score

> Compute the calinski_harabasz_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute calinski_harabasz_score, or asks how to score with calinski_harabasz_score.

- Skill: `qhjqhj00/calinski-harabasz-score` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/calinski-harabasz-score`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/calinski-harabasz-score/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/calinski-harabasz-score

---


# calinski-harabasz-score

> Metric `calinski_harabasz_score` from `scikit-learn` (sklearn.metrics.calinski_harabasz_score)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with calinski_harabasz_score, or
mentions `sklearn.metrics.calinski_harabasz_score` directly, or wants the standard scikit-learn implementation.

## Reference signature

```python
from sklearn.metrics import calinski_harabasz_score

# calinski_harabasz_score(X, labels)
```

## Library docstring

```
Compute the Calinski and Harabasz score.

It is also known as the Variance Ratio Criterion.

The score is defined as ratio of the sum of between-cluster dispersion and
of within-cluster dispersion.

Read more in the :ref:`User Guide <calinski_harabasz_index>`.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    A list of ``n_features``-dimensional data points. Each row corresponds
    to a single data point.

labels : array-like of shape (n_samples,)
    Predicted labels for each sample.

Returns
-------
score : float
    The resulting Calinski-Harabasz score.

References
----------
.. [1] `T. Calinski and J. Harabasz, 1974. "A dendrite method for cluster
   analysis". Communications in Statistics
   <https://www.tandfonline.com/doi/abs/10.1080/03610927408827101>`_

Examples
--------
>>> from sklearn.datasets import make_blobs
>>> from sklearn.cluster import KMeans
>>> from sklearn.metrics import calinski_harabasz_score
>>> X, _ = make_blobs(random_state=0)
>>> kmeans = KMeans(n_clusters=3, random_state=0,).fit(X)
>>> calinski_harabasz_score(X, kmeans.labels_)
114.8...
```

## Quick recipe

```python
import sklearn.metrics as _m
score = _m.calinski_harabasz_score(y_true, y_pred)
```

## Don'ts

- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.

