Compute the DaviesBouldinScore metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute DaviesBouldinScore, or asks how to score with DaviesBouldinScore.
Scanned 9/11/2026
Install to Claude Code
npx -y skills add qhjqhj00/research-skills-pool --skill daviesbouldinscore --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Daviesbouldinscore?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-daviesbouldinscore)More formats (shields.io, HTML) on the badges page.
---
name: daviesbouldinscore
description: Compute the DaviesBouldinScore metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute DaviesBouldinScore, or asks how to score with DaviesBouldinScore.
metadata:
skill_kind: metric
source_lib: torchmetrics
import_path: torchmetrics.clustering.DaviesBouldinScore
source: library_introspection
---
# daviesbouldinscore
> Metric `DaviesBouldinScore` from `torchmetrics` (torchmetrics.clustering.DaviesBouldinScore)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with DaviesBouldinScore, or
mentions `torchmetrics.clustering.DaviesBouldinScore` directly, or wants the standard torchmetrics implementation.
## Reference signature
```python
from torchmetrics.clustering import DaviesBouldinScore
# DaviesBouldinScore(**kwargs: Any) -> None
```
## Library docstring
```
Compute `Davies-Bouldin Score`_ for clustering algorithms.
Given the following quantities:
.. math::
S_i = \left( \frac{1}{T_i} \sum_{j=1}^{T_i} ||X_j - A_i||^2_2 \right)^{1/2}
where :math:`T_i` is the number of samples in cluster :math:`i`, :math:`X_j` is the :math:`j`-th sample in cluster
:math:`i`, and :math:`A_i` is the centroid of cluster :math:`i`. This quantity is the average distance between all
the samples in cluster :math:`i` and its centroid. Let
.. math::
M_{i,j} = ||A_i - A_j||_2
e.g. the distance between the centroids of cluster :math:`i` and cluster :math:`j`. Then the Davies-Bouldin score
is defined as:
.. math::
DB = \frac{1}{n_{clusters}} \sum_{i=1}^{n_{clusters}} \max_{j \neq i} \left( \frac{S_i + S_j}{M_{i,j}} \right)
This clustering metric is an intrinsic measure, because it does not rely on ground truth labels for the evaluation.
Instead it examines how well the clusters are separated from each other. The score is higher when clusters are dense
and well separated, which relates to a standard concept of a cluster.
As input to ``forward`` and ``update`` the metric accepts the following input:
- ``data`` (:class:`~torch.Tensor`): float tensor with shape ``(N,d)`` with the embedded data. ``d`` is the
dimensionality of the embedding space.
- ``labels`` (:class:`~torch.Tensor`): single integer tensor with shape ``(N,)`` with cluster labels
As output of ``forward`` and ``compute`` the metric returns the following output:
- ``chs`` (:class:`~torch.Tensor`): A tensor with the Calinski Harabasz Score
Args:
kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.
Example::
>>> from torch import randn, randint
>>> from torchmetrics.clustering import DaviesBouldinScore
>>> data = randn(10, 3)
>>> labels = randint(3, (10,))
>>> metric = DaviesBouldinScore()
>>> metric(data, labels)
tensor(1.2540)
```
## Quick recipe
```python
import torchmetrics.clustering as _m
score = _m.DaviesBouldinScore(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)`.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!