# Weightedtau

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

- Skill: `qhjqhj00/weightedtau` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/weightedtau`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/weightedtau/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/weightedtau

---


# weightedtau

> Metric `weightedtau` from `scipy.stats` (scipy.stats.weightedtau)

## When to invoke this skill

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

## Reference signature

```python
from scipy.stats import weightedtau

# weightedtau(x, y, rank=True, weigher=None, additive=True, *, axis=None, nan_policy='propagate', keepdims=False)
```

## Library docstring

```
Compute a weighted version of Kendall's :math:`\tau`.

The weighted :math:`\tau` is a weighted version of Kendall's
:math:`\tau` in which exchanges of high weight are more influential than
exchanges of low weight. The default parameters compute the additive
hyperbolic version of the index, :math:`\tau_\mathrm h`, which has
been shown to provide the best balance between important and
unimportant elements [1]_.

The weighting is defined by means of a rank array, which assigns a
nonnegative rank to each element (higher importance ranks being
associated with smaller values, e.g., 0 is the highest possible rank),
and a weigher function, which assigns a weight based on the rank to
each element. The weight of an exchange is then the sum or the product
of the weights of the ranks of the exchanged elements. The default
parameters compute :math:`\tau_\mathrm h`: an exchange between
elements with rank :math:`r` and :math:`s` (starting from zero) has
weight :math:`1/(r+1) + 1/(s+1)`.

Specifying a rank array is meaningful only if you have in mind an
external criterion of importance. If, as it usually happens, you do
not have in mind a specific rank, the weighted :math:`\tau` is
defined by averaging the values obtained using the decreasing
lexicographical rank by (`x`, `y`) and by (`y`, `x`). This is the
behavior with default parameters. Note that the convention used
here for ranking (lower values imply higher importance) is opposite
to that used by other SciPy statistical functions.

Parameters
----------
x, y : array_like
    Arrays of scores, of the same shape. If arrays are not 1-D, they will
    be flattened to 1-D.
rank : array_like of ints or bool, optional
    A nonnegative rank assigned to each element. If it is None, the
    decreasing lexicographical rank by (`x`, `y`) will be used: elements of
    higher rank will be those with larger `x`-values, using `y`-values to
    break ties (in particular, swapping `x` and `y` will give a different
    result). If it is False, the element indices will be used
    directly as ranks. The default is True, in which case this
    function returns the average of the values obtained using the
    decreasing lexicographical rank b
```

## Quick recipe

```python
import scipy.stats as _m
score = _m.weightedtau(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)`.

