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.
Installs into .claude/skills of the current project.
Are you the author of Minkowskidistance?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-minkowskidistance)
---
name: minkowskidistance
description: 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.
metadata:
skill_kind: metric
source_lib: torchmetrics
import_path: torchmetrics.MinkowskiDistance
source: library_introspection
---
# 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)`.