# Kendalltau

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

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

---


# kendalltau

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

## When to invoke this skill

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

## Reference signature

```python
from scipy.stats import kendalltau

# kendalltau(x, y, *, nan_policy='propagate', method='auto', variant='b', alternative='two-sided', axis=None, keepdims=False)
```

## Library docstring

```
Calculate Kendall's tau, a correlation measure for ordinal data.

Kendall's tau is a measure of the correspondence between two rankings.
Values close to 1 indicate strong agreement, and values close to -1
indicate strong disagreement. This implements two variants of Kendall's
tau: tau-b (the default) and tau-c (also known as Stuart's tau-c). These
differ only in how they are normalized to lie within the range -1 to 1;
the hypothesis tests (their p-values) are identical. Kendall's original
tau-a is not implemented separately because both tau-b and tau-c reduce
to tau-a in the absence of ties.

Although a naive implementation has O(n^2) complexity, this implementation
uses a Fenwick tree to do the computation in O(n log(n)) complexity.

Parameters
----------
x, y : array_like
    Arrays of rankings, of the same shape. If arrays are not 1-D, they
    will be flattened to 1-D.
nan_policy : {'propagate', 'omit', 'raise'}
    Defines how to handle input NaNs.

    - ``propagate``: if a NaN is present in the axis slice (e.g. row) along
      which the  statistic is computed, the corresponding entry of the output
      will be NaN.
    - ``omit``: NaNs will be omitted when performing the calculation.
      If insufficient data remains in the axis slice along which the
      statistic is computed, the corresponding entry of the output will be
      NaN.
    - ``raise``: if a NaN is present, a ``ValueError`` will be raised.
method : {'auto', 'asymptotic', 'exact'}, optional
    Defines which method is used to calculate the p-value [5]_.
    The following options are available (default is 'auto'):

    * 'auto': selects the appropriate method based on a trade-off
      between speed and accuracy
    * 'asymptotic': uses a normal approximation valid for large samples
    * 'exact': computes the exact p-value, but can only be used if no ties
      are present. As the sample size increases, the 'exact' computation
      time may grow and the result may lose some precision.
variant : {'b', 'c'}, optional
    Defines which variant of Kendall's tau is returned. Default is 'b'.
alternative : {'two-sided', 'less', 'greater'}, optional
    Defines the alternative hypothesis. Defaul
```

## Quick recipe

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

