# V-Measure Score¶

## Module Interface¶

class torchmetrics.clustering.VMeasureScore(beta=1.0, **kwargs)[source]

Compute V-Measure Score.

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): single integer tensor with shape (N,) with predicted cluster labels

• target (Tensor): single integer tensor with shape (N,) with ground truth cluster labels

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

Parameters:
Example::
>>> 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)[source]

Plot a single or multiple values from the metric.

Parameters:
Return type:
Returns:

Figure and Axes object

Raises:

ModuleNotFoundError – If matplotlib is not installed

>>> # 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())

>>> # 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)


## Functional Interface¶

torchmetrics.functional.clustering.v_measure_score(preds, target, beta=1.0)[source]

Compute the V-measure score between two clusterings.

Parameters:
Return type:

Tensor

Returns:

scalar tensor with the rand score

Example

>>> 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)