Skip to content
Back to skills

Mutual Info Score

ASecurity

Compute the mutual_info_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute mutual_info_score, or asks how to score with mutual_info_score.

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 11, 2026
documentationpython

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill mutual-info-score --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mutual Info Score?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Mutual Info Score
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-mutual-info-score/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-mutual-info-score)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: mutual-info-score
description: Compute the mutual_info_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute mutual_info_score, or asks how to score with mutual_info_score.
metadata:
  skill_kind: metric
  source_lib: scikit-learn
  import_path: sklearn.metrics.mutual_info_score
  source: library_introspection
---

# mutual-info-score

> Metric `mutual_info_score` from `scikit-learn` (sklearn.metrics.mutual_info_score)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with mutual_info_score, or
mentions `sklearn.metrics.mutual_info_score` directly, or wants the standard scikit-learn implementation.

## Reference signature

```python
from sklearn.metrics import mutual_info_score

# mutual_info_score(labels_true, labels_pred, *, contingency=None)
```

## Library docstring

```
Mutual Information between two clusterings.

The Mutual Information is a measure of the similarity between two labels
of the same data. Where :math:`|U_i|` is the number of the samples
in cluster :math:`U_i` and :math:`|V_j|` is the number of the
samples in cluster :math:`V_j`, the Mutual Information
between clusterings :math:`U` and :math:`V` is given as:

.. math::

    MI(U,V)=\sum_{i=1}^{|U|} \sum_{j=1}^{|V|} \frac{|U_i\cap V_j|}{N}
    \log\frac{N|U_i \cap V_j|}{|U_i||V_j|}

This metric is independent of the absolute values of the labels:
a permutation of the class or cluster label values won't change the
score value in any way.

This metric is furthermore symmetric: switching :math:`U` (i.e
``label_true``) with :math:`V` (i.e. ``label_pred``) will return the
same score value. This can be useful to measure the agreement of two
independent label assignments strategies on the same dataset when the
real ground truth is not known.

Read more in the :ref:`User Guide <mutual_info_score>`.

Parameters
----------
labels_true : array-like of shape (n_samples,), dtype=integral
    A clustering of the data into disjoint subsets, called :math:`U` in
    the above formula.

labels_pred : array-like of shape (n_samples,), dtype=integral
    A clustering of the data into disjoint subsets, called :math:`V` in
    the above formula.

contingency : {array-like, sparse matrix} of shape             (n_classes_true, n_classes_pred), default=None
    A contingency matrix given by the
    :func:`~sklearn.metrics.cluster.contingency_matrix` function. If value
    is ``None``, it will be computed, otherwise the given value is used,
    with ``labels_true`` and ``labels_pred`` ignored.

Returns
-------
mi : float
   Mutual information, a non-negative value, measured in nats using the
   natural logarithm.

See Also
--------
adjusted_mutual_info_score : Adjusted against chance Mutual Information.
normalized_mutual_info_score : Normalized Mutual Information.

Notes
-----
The logarithm used is the natural logarithm (base-e).

Examples
--------
>>> from sklearn.metrics import mutual_info_score
>>> labels_true = [0, 1, 1, 0, 1, 0]
>>> labels_pred = [0, 1, 0, 0, 1, 1]
>>> mutual_info_scor
```

## Quick recipe

```python
import sklearn.metrics as _m
score = _m.mutual_info_score(y_true, y_pred)
```

## Don'ts

- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.