Skip to content
Back to skills

Multiclassconfusionmatrix

ASecurity

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

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 11, 2026
documentationpythongit

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill multiclassconfusionmatrix --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Multiclassconfusionmatrix?

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

Security grade badge for Multiclassconfusionmatrix
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-multiclassconfusionmatrix/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-multiclassconfusionmatrix)

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: multiclassconfusionmatrix
description: Compute the MulticlassConfusionMatrix metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute MulticlassConfusionMatrix, or asks how to score with MulticlassConfusionMatrix.
metadata:
  skill_kind: metric
  source_lib: torchmetrics
  import_path: torchmetrics.classification.MulticlassConfusionMatrix
  source: library_introspection
---

# multiclassconfusionmatrix

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

## When to invoke this skill

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

## Reference signature

```python
from torchmetrics.classification import MulticlassConfusionMatrix

# MulticlassConfusionMatrix(num_classes: int, 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 multiclass 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 multiclass tasks, the confusion matrix is a NxN matrix, where:

- :math:`C_{i, i}` represents the number of true positives for class :math:`i`
- :math:`\sum_{j=1, j\neq i}^N C_{i, j}` represents the number of false negatives for class :math:`i`
- :math:`\sum_{j=1, j\neq i}^N C_{j, i}` represents the number of false positives for class :math:`i`
- the sum of the remaining cells in the matrix represents the number of true negatives for class :math:`i`

As input to ``forward`` and ``update`` the metric accepts the following input:

- ``preds`` (:class:`~torch.Tensor`): An int or float tensor of shape ``(N, ...)``. 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`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, ...)``.

As output to ``forward`` and ``compute`` the metric returns the following output:

- ``confusion_matrix``: [num_classes, num_classes] matrix

Args:
    num_classes: Integer specifying the number of classes
    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.

Exampl
```

## Quick recipe

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