# Fowlkes-Mallows Index¶

## Module Interface¶

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

Compute Fowlkes-Mallows Index.

$FMI(U,V) = \frac{TP}{\sqrt{(TP + FP) * (TP + FN)}}$

Where $$TP$$ is the number of true positives, $$FP$$ is the number of false positives, and $$FN$$ is the number of false negatives.

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:

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

Example::
>>> import torch
>>> from torchmetrics.clustering import FowlkesMallowsIndex
>>> preds = torch.tensor([2, 2, 0, 1, 0])
>>> target = torch.tensor([2, 2, 1, 1, 0])
>>> fmi = FowlkesMallowsIndex()
>>> fmi(preds, target)
tensor(0.5000)

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 FowlkesMallowsIndex
>>> metric = FowlkesMallowsIndex()
>>> 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 FowlkesMallowsIndex
>>> metric = FowlkesMallowsIndex()
>>> 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.fowlkes_mallows_index(preds, target)[source]

Compute Fowlkes-Mallows index between two clusterings.

Parameters:
Return type:

Tensor

Returns:

Scalar tensor with Fowlkes-Mallows index

Example

>>> import torch
>>> from torchmetrics.functional.clustering import fowlkes_mallows_index
>>> preds = torch.tensor([2, 2, 0, 1, 0])
>>> target = torch.tensor([2, 2, 1, 1, 0])
>>> fowlkes_mallows_index(preds, target)
tensor(0.5000)