---
title: V-Measure Score
description: Compute V-Measure Score.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/clustering/v_measure_score'
---
# V-Measure Score {#v-measure-score}

## Module Interface {#module-interface}

### `class torchmetrics.clustering.VMeasureScore(beta=1.0, **kwargs)` {#torchmetrics.clustering.VMeasureScore}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/clustering/homogeneity_completeness_v_measure.py#L226-L329)

Compute [V-Measure Score](https://www.semanticscholar.org/paper/V-Measure%3A-A-Conditional-Entropy-Based-External-Rosenberg-Hirschberg/5421dbcb7e14766eb3d951910ae8d7892d735a01).

The V-measure is the harmonic mean between homogeneity and completeness:

```math
v = \frac{(1 + \beta) * homogeneity * completeness}{\beta * homogeneity + completeness}
```

where $`\beta`$ is a weight parameter that defines the weight of homogeneity in the harmonic mean, with the default value $`\beta=1`$. The V-measure is symmetric, which means that swapping `preds` and `target` does not change the score.

This clustering metric is an extrinsic measure, because it requires ground truth clustering labels, which may not be available in practice since clustering in generally is used for unsupervised learning.

As input to `forward` and `update` the metric accepts the following input:

*   `preds` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): single integer tensor with shape `(N,)` with predicted cluster labels
    
*   `target` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): single integer tensor with shape `(N,)` with ground truth cluster labels
    

As output of `forward` and `compute` the metric returns the following output:

*   `rand_score` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A tensor with the Rand Score
    

Parameters:

*   **beta** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Weight parameter that defines the weight of homogeneity in the harmonic mean
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Example::

```python
>>> import torch
>>> from torchmetrics.clustering import VMeasureScore
>>> preds = torch.tensor([2, 1, 0, 1, 0])
>>> target = torch.tensor([0, 2, 1, 1, 0])
>>> metric = VMeasureScore(beta=2.0)
>>> metric(preds, target)
tensor(0.4744)
```

#### `plot(val=None, ax=None)` {#torchmetrics.clustering.VMeasureScore.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/clustering/homogeneity_completeness_v_measure.py#L291-L329)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.
    
*   **ax** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> # Example plotting a single value
>>> import torch
>>> from torchmetrics.clustering import VMeasureScore
>>> metric = VMeasureScore()
>>> metric.update(torch.randint(0, 4, (10,)), torch.randint(0, 4, (10,)))
>>> fig_, ax_ = metric.plot(metric.compute())
```

[![../../\_images/v\_measure\_score-1.png](/docs/torchmetrics/1.9.0/static/_images/v_measure_score-1.png)](/docs/torchmetrics/1.9.0/static/_images/v_measure_score-1.png)

```python
>>> # Example plotting multiple values
>>> import torch
>>> from torchmetrics.clustering import VMeasureScore
>>> metric = VMeasureScore()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(torch.randint(0, 4, (10,)), torch.randint(0, 4, (10,))))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/v\_measure\_score-2.png](/docs/torchmetrics/1.9.0/static/_images/v_measure_score-2.png)](/docs/torchmetrics/1.9.0/static/_images/v_measure_score-2.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.clustering.v_measure_score(preds, target, beta=1.0)` {#torchmetrics.functional.clustering.v_measure_score}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/clustering/homogeneity_completeness_v_measure.py#L91-L114)

Compute the V-measure score between two clusterings.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – predicted cluster labels
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – ground truth cluster labels
    
*   **beta** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – weight of the harmonic mean between homogeneity and completeness
    

Return type:

[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

Returns:

scalar tensor with the rand score

Example

```python
>>> from torchmetrics.functional.clustering import v_measure_score
>>> import torch
>>> v_measure_score(torch.tensor([0, 0, 1, 1]), torch.tensor([1, 1, 0, 0]))
tensor(1.)
>>> v_measure_score(torch.tensor([0, 0, 1, 2]), torch.tensor([0, 0, 1, 1]))
tensor(0.8000)
```

---

**Navigation**

- Parent: [Clustering](/docs/torchmetrics/1.9.0/clustering.md)
