wilcoxon
Metric
wilcoxonfromscipy.stats(scipy.stats.wilcoxon)
When to invoke this skill
The user has predictions + ground truth and asks to evaluate with wilcoxon, or
mentions scipy.stats.wilcoxon directly, or wants the standard scipy.stats implementation.
Reference signature
from scipy.stats import wilcoxon
# wilcoxon(x, y=None, zero_method='wilcox', correction=False, alternative='two-sided', method='auto', *, axis=0, nan_policy='propagate', keepdims=False)
Library docstring
Calculate the Wilcoxon signed-rank test.
The Wilcoxon signed-rank test tests the null hypothesis that two
related paired samples come from the same distribution. In particular,
it tests whether the distribution of the differences ``x - y`` is symmetric
about zero. It is a non-parametric version of the paired T-test.
Parameters
----------
x : array_like
Either the first set of measurements (in which case ``y`` is the second
set of measurements), or the differences between two sets of
measurements (in which case ``y`` is not to be specified.) Must be
one-dimensional.
y : array_like, optional
Either the second set of measurements (if ``x`` is the first set of
measurements), or not specified (if ``x`` is the differences between
two sets of measurements.) Must be one-dimensional.
.. warning::
When `y` is provided, `wilcoxon` calculates the test statistic
based on the ranks of the absolute values of ``d = x - y``.
Roundoff error in the subtraction can result in elements of ``d``
being assigned different ranks even when they would be tied with
exact arithmetic. Rather than passing `x` and `y` separately,
consider computing the difference ``x - y``, rounding as needed to
ensure that only truly unique elements are numerically distinct,
and passing the result as `x`, leaving `y` at the default (None).
zero_method : {"wilcox", "pratt", "zsplit"}, optional
There are different conventions for handling pairs of observations
with equal values ("zero-differences", or "zeros").
* "wilcox": Discards all zero-differences (default); see [4]_.
* "pratt": Includes zero-differences in the ranking process,
but drops the ranks of the zeros (more conservative); see [3]_.
In this case, the normal approximation is adjusted as in [5]_.
* "zsplit": Includes zero-differences in the ranking process and
splits the zero rank between positive and negative ones.
correction : bool, optional
If True, apply continuity correction by adjusting the Wilcoxon rank
statistic by 0.5 towards the mean value when computing the
z-statistic if a normal approximat
Quick recipe
import scipy.stats as _m
score = _m.wilcoxon(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).