---
title: Adjusted Mutual Information Score
description: Compute Adjusted Mutual Information Score.
canonical: >-
  https://lightning.ai/docs/torchmetrics/stable/clustering/adjusted_mutual_info_score
---
# Adjusted Mutual Information Score {#adjusted-mutual-information-score}

## Module Interface {#module-interface}

### `class torchmetrics.clustering.AdjustedMutualInfoScore(average_method='arithmetic', **kwargs)` {#torchmetrics.clustering.AdjustedMutualInfoScore}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/clustering/adjusted_mutual_info_score.py#L32-L128)

Compute [Adjusted Mutual Information Score](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.adjusted_mutual_info_score.html#sklearn.metrics.adjusted_mutual_info_score).

```math
AMI(U,V) = \frac{MI(U,V) - E(MI(U,V))}{avg(H(U), H(V)) - E(MI(U,V))}
```

Where $`U`$ is a tensor of target values, $`V`$ is a tensor of predictions, $`M_p(U,V)`$ is the generalized mean of order $`p`$ of $`U`$ and $`V`$, and $`MI(U,V)`$ is the mutual information score between clusters $`U`$ and $`V`$. The metric is symmetric, therefore swapping $`U`$ and $`V`$ yields the same mutual information 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:

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

Parameters:

*   **average\_method** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'min'`, `'geometric'`, `'arithmetic'`, `'max'`\]) – Method used to calculate generalized mean for normalization. Choose between `'min'`, `'geometric'`, `'arithmetic'`, `'max'`.
    
*   **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 AdjustedMutualInfoScore
>>> preds = torch.tensor([2, 1, 0, 1, 0])
>>> target = torch.tensor([0, 2, 1, 1, 0])
>>> ami_score = AdjustedMutualInfoScore(average_method="arithmetic")
>>> ami_score(preds, target)
tensor(-0.2500)
```

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

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/clustering/adjusted_mutual_info_score.py#L90-L128)

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 AdjustedMutualInfoScore
>>> metric = AdjustedMutualInfoScore()
>>> metric.update(torch.randint(0, 4, (10,)), torch.randint(0, 4, (10,)))
>>> fig_, ax_ = metric.plot(metric.compute())
```

[![../../\_images/adjusted\_mutual\_info\_score-1.png](/docs/torchmetrics/1.9.0/static/_images/adjusted_mutual_info_score-1.png)](/docs/torchmetrics/1.9.0/static/_images/adjusted_mutual_info_score-1.png)

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

[![../../\_images/adjusted\_mutual\_info\_score-2.png](/docs/torchmetrics/1.9.0/static/_images/adjusted_mutual_info_score-2.png)](/docs/torchmetrics/1.9.0/static/_images/adjusted_mutual_info_score-2.png)

#### `higher_is_better: Optional[bool] = None` {#torchmetrics.clustering.AdjustedMutualInfoScore.higher_is_better}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/torchmetrics/clustering.py)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.clustering.adjusted_mutual_info_score(preds, target, average_method='arithmetic')` {#torchmetrics.functional.clustering.adjusted_mutual_info_score}

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

Compute adjusted mutual information 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
    
*   **average\_method** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'min'`, `'geometric'`, `'arithmetic'`, `'max'`\]) – normalizer computation method
    

Return type:

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

Returns:

Scalar tensor with adjusted mutual info score between 0.0 and 1.0

Example

```python
>>> from torchmetrics.functional.clustering import adjusted_mutual_info_score
>>> preds = torch.tensor([2, 1, 0, 1, 0])
>>> target = torch.tensor([0, 2, 1, 1, 0])
>>> adjusted_mutual_info_score(preds, target, "arithmetic")
tensor(-0.2500)
```

---

**Navigation**

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