Skip to content
Back to skills

Classwisewrapper

ASecurity

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

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

Security analysis

A100/100

Scanned September 11, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Classwisewrapper?

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

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

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

# classwisewrapper

> Metric `ClasswiseWrapper` from `torchmetrics` (torchmetrics.ClasswiseWrapper)

## When to invoke this skill

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

## Reference signature

```python
from torchmetrics import ClasswiseWrapper

# ClasswiseWrapper(metric: torchmetrics.metric.Metric, labels: Optional[list[str]] = None, prefix: Optional[str] = None, postfix: Optional[str] = None) -> None
```

## Library docstring

```
Wrapper metric for altering the output of classification metrics.

This metric works together with classification metrics that returns multiple values (one value per class) such that
label information can be automatically included in the output.

Args:
    metric: base metric that should be wrapped. It is assumed that the metric outputs a single
        tensor that is split along the first dimension.
    labels: list of strings indicating the different classes.
    prefix: string that is prepended to the metric names.
    postfix: string that is appended to the metric names.

Example::
    Basic example where the output of a metric is unwrapped into a dictionary with the class index as keys:

    >>> from torch import randint, randn
    >>> from torchmetrics.wrappers import ClasswiseWrapper
    >>> from torchmetrics.classification import MulticlassAccuracy
    >>> metric = ClasswiseWrapper(MulticlassAccuracy(num_classes=3, average=None))
    >>> preds = randn(10, 3).softmax(dim=-1)
    >>> target = randint(3, (10,))
    >>> metric(preds, target)  # doctest: +NORMALIZE_WHITESPACE
    {'multiclassaccuracy_0': tensor(0.5000),
     'multiclassaccuracy_1': tensor(0.7500),
     'multiclassaccuracy_2': tensor(0.)}

Example::
    Using custom name via prefix and postfix:

    >>> from torch import randint, randn
    >>> from torchmetrics.wrappers import ClasswiseWrapper
    >>> from torchmetrics.classification import MulticlassAccuracy
    >>> metric_pre = ClasswiseWrapper(MulticlassAccuracy(num_classes=3, average=None), prefix="acc-")
    >>> metric_post = ClasswiseWrapper(MulticlassAccuracy(num_classes=3, average=None), postfix="-acc")
    >>> preds = randn(10, 3).softmax(dim=-1)
    >>> target = randint(3, (10,))
    >>> metric_pre(preds, target)  # doctest: +NORMALIZE_WHITESPACE
    {'acc-0': tensor(0.3333), 'acc-1': tensor(0.6667), 'acc-2': tensor(0.)}
    >>> metric_post(preds, target)  # doctest: +NORMALIZE_WHITESPACE
    {'0-acc': tensor(0.3333), '1-acc': tensor(0.6667), '2-acc': tensor(0.)}

Example::
    Providing labels as a list of strings:

    >>> from torch import randint, randn
    >>> from torchmetrics.wrappers import ClasswiseWrapper
    >>> from torch
```

## Quick recipe

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