# Multilabelconfusionmatrix

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

- Skill: `qhjqhj00/multilabelconfusionmatrix` (Agent Skill)
- Install (CLI): `npx get-skill add qhjqhj00/multilabelconfusionmatrix`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/multilabelconfusionmatrix/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/qhjqhj00/multilabelconfusionmatrix

---


# multilabelconfusionmatrix

> Metric `MultilabelConfusionMatrix` from `torchmetrics` (torchmetrics.classification.MultilabelConfusionMatrix)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with MultilabelConfusionMatrix, or
mentions `torchmetrics.classification.MultilabelConfusionMatrix` directly, or wants the standard torchmetrics implementation.

## Reference signature

```python
from torchmetrics.classification import MultilabelConfusionMatrix

# MultilabelConfusionMatrix(num_labels: int, threshold: float = 0.5, ignore_index: Optional[int] = None, normalize: Optional[Literal['true', 'pred', 'all', 'none']] = None, validate_args: bool = True, **kwargs: Any) -> None
```

## Library docstring

```
Compute the `confusion matrix`_ for multilabel tasks.

The confusion matrix :math:`C` is constructed such that :math:`C_{i, j}` is equal to the number of observations
known to be in class :math:`i` but predicted to be in class :math:`j`. Thus row indices of the confusion matrix
correspond to the true class labels and column indices correspond to the predicted class labels.

For multilabel tasks, the confusion matrix is a Nx2x2 tensor, where each 2x2 matrix corresponds to the confusion
for that label. The structure of each 2x2 matrix is as follows:

- :math:`C_{0, 0}`: True negatives
- :math:`C_{0, 1}`: False positives
- :math:`C_{1, 0}`: False negatives
- :math:`C_{1, 1}`: True positives

As input to 'update' the metric accepts the following input:

- ``preds`` (int or float tensor): ``(N, C, ...)``. If preds is a floating point tensor with values outside
  [0,1] range we consider the input to be logits and will auto apply sigmoid per element. Additionally,
  we convert to int tensor with thresholding using the value in ``threshold``.
- ``target`` (int tensor): ``(N, C, ...)``

As output of 'compute' the metric returns the following output:

- ``confusion matrix``: [num_labels,2,2] matrix

Args:
    num_classes: Integer specifying the number of labels
    threshold: Threshold for transforming probability to binary (0,1) predictions
    ignore_index:
        Specifies a target value that is ignored and does not contribute to the metric calculation
    normalize: Normalization mode for confusion matrix. Choose from:

        - ``None`` or ``'none'``: no normalization (default)
        - ``'true'``: normalization over the targets (most commonly used)
        - ``'pred'``: normalization over the predictions
        - ``'all'``: normalization over the whole matrix
    validate_args: bool indicating if input arguments and tensors should be validated for correctness.
        Set to ``False`` for faster computations.
    kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

Example (preds is int tensor):
    >>> from torch import tensor
    >>> from torchmetrics.classification import MultilabelConfusionMatrix
    >>> target = tensor([[0, 1, 0], 
```

## Quick recipe

```python
import torchmetrics.classification as _m
score = _m.MultilabelConfusionMatrix(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)`.

