Completeness Score

Module Interface

class torchmetrics.clustering.CompletenessScore(**kwargs)[source]

Compute Completeness Score.

A clustering result satisfies completeness if all the data points that are members of a given class are elements of the same cluster. The metric is not symmetric, therefore swapping preds and target yields a different 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:

  • rand_score (Tensor): A tensor with the Rand Score


kwargs (Any) – Additional keyword arguments, see Advanced metric settings for more info.


>>> import torch
>>> from torchmetrics.clustering import CompletenessScore
>>> preds = torch.tensor([2, 1, 0, 1, 0])
>>> target = torch.tensor([0, 2, 1, 1, 0])
>>> metric = CompletenessScore()
>>> metric(preds, target)
plot(val=None, ax=None)[source]

Plot a single or multiple values from the metric.

  • val (Union[Tensor, Sequence[Tensor], None]) – 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[Axes]) – An matplotlib axis object. If provided will add plot to that axis

Return type:

Tuple[Figure, Union[Axes, ndarray]]


Figure and Axes object


ModuleNotFoundError – If matplotlib is not installed

>>> # Example plotting a single value
>>> import torch
>>> from torchmetrics.clustering import CompletenessScore
>>> metric = CompletenessScore()
>>> 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 CompletenessScore
>>> metric = CompletenessScore()
>>> 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.completeness_score(preds, target)[source]

Compute the Completeness score between two clusterings.

  • preds (Tensor) – predicted cluster labels

  • target (Tensor) – ground truth cluster labels

Return type:



scalar tensor with the rand score


>>> from torchmetrics.functional.clustering import completeness_score
>>> import torch
>>> completeness_score(torch.tensor([0, 0, 1, 1]), torch.tensor([1, 1, 0, 0]))
>>> completeness_score(torch.tensor([0, 0, 1, 2]), torch.tensor([0, 0, 1, 1]))