Skip to content
Back to skills

Dunnindex

ASecurity

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

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 11, 2026
documentationpython

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill dunnindex --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dunnindex?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Dunnindex
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-dunnindex/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-dunnindex)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: dunnindex
description: Compute the DunnIndex metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute DunnIndex, or asks how to score with DunnIndex.
metadata:
  skill_kind: metric
  source_lib: torchmetrics
  import_path: torchmetrics.clustering.DunnIndex
  source: library_introspection
---

# dunnindex

> Metric `DunnIndex` from `torchmetrics` (torchmetrics.clustering.DunnIndex)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with DunnIndex, or
mentions `torchmetrics.clustering.DunnIndex` directly, or wants the standard torchmetrics implementation.

## Reference signature

```python
from torchmetrics.clustering import DunnIndex

# DunnIndex(p: float = 2, **kwargs: Any) -> None
```

## Library docstring

```
Compute `Dunn Index`_.

.. math::
    DI_m = \frac{\min_{1\leq i<j\leq m} \delta(C_i,C_j)}{\max_{1\leq k\leq m} \Delta_k}

Where :math:`C_i` is a cluster of tensors, :math:`C_j` is a cluster of tensors,
and :math:`\delta(C_i,C_j)` is the intercluster distance metric for :math:`m` clusters.

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:

- ``dunn_index`` (:class:`~torch.Tensor`): A tensor with the Dunn Index

Args:
    kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

Example::
    >>> import torch
    >>> from torchmetrics.clustering import DunnIndex
    >>> data = torch.tensor([[0, 0], [0.5, 0], [1, 0], [0.5, 1]])
    >>> labels = torch.tensor([0, 0, 0, 1])
    >>> dunn_index = DunnIndex(p=2)
    >>> dunn_index(data, labels)
    tensor(2.)
```

## Quick recipe

```python
import torchmetrics.clustering as _m
score = _m.DunnIndex(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)`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.