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.
Scanned 9/11/2026
Install to Claude Code
npx -y skills add qhjqhj00/research-skills-pool --skill multilabelconfusionmatrix --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Multilabelconfusionmatrix?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-multilabelconfusionmatrix)More formats (shields.io, HTML) on the badges page.
---
name: multilabelconfusionmatrix
description: 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.
metadata:
skill_kind: metric
source_lib: torchmetrics
import_path: torchmetrics.classification.MultilabelConfusionMatrix
source: library_introspection
---
# 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)`.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!