# Minkowskidistance

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

- Skill: `qhjqhj00/minkowskidistance` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/minkowskidistance`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/minkowskidistance/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/minkowskidistance

---


# minkowskidistance

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

## When to invoke this skill

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

## Reference signature

```python
from torchmetrics import MinkowskiDistance

# MinkowskiDistance(p: float, **kwargs: Any) -> None
```

## Library docstring

```
Compute `Minkowski Distance`_.

.. math::
    d_{\text{Minkowski}} = \sum_{i}^N (| y_i - \hat{y_i} |^p)^\frac{1}{p}

where
    :math: `y` is a tensor of target values,
    :math: `\hat{y}` is a tensor of predictions,
    :math: `\p` is a non-negative integer or floating-point number

This metric can be seen as generalized version of the standard euclidean distance which corresponds to minkowski
distance with p=2.

Args:
    p: int or float larger than 1, exponent to which the difference between preds and target is to be raised
    kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

Example:
    >>> from torchmetrics.regression import MinkowskiDistance
    >>> target = tensor([1.0, 2.8, 3.5, 4.5])
    >>> preds = tensor([6.1, 2.11, 3.1, 5.6])
    >>> minkowski_distance = MinkowskiDistance(3)
    >>> minkowski_distance(preds, target)
    tensor(5.1220)
```

## Quick recipe

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

