tau_x_score#
- sklr.metrics.tau_x_score(y_true: ArrayLike, y_pred: ArrayLike, *, sample_weight: ArrayLike | None = None) float#
Compute the \(\tau_x\) coefficient between partial label rankings.
The \(\tau_x\) rank correlation coefficient [emond_new_2002] extends Kendall’s \(\tau\) to rankings with ties. It scores each ordered pair of different labels with
+1if both rankings agree on whether the first label is ahead of or tied with the second one, and with-1otherwise, and divides the total score by the number of ordered pairs. It ranges from-1to1, which it reaches when both rankings are equal, and it is equal to Kendall’s \(\tau\) for rankings without ties. It is only-1when one ranking is the reverse of the other and neither has ties, because two tied labels are each ahead of or tied with the other, so the pairs that they form cannot disagree in both orders. The score of the rankings is the average of the coefficients of their samples.Read more in the User Guide.
- Parameters:
- y_truearray-like of shape (n_samples, n_labels)
The true rankings, complete and possibly with ties, as described in Ranking representation.
- y_predarray-like of shape (n_samples, n_labels)
The predicted rankings, complete and possibly with ties.
- sample_weightarray-like of shape (n_samples,), default=None
Non-negative weights of the samples in the average. If
None, the samples are equally weighted.
- Returns:
- scorefloat
The average \(\tau_x\) of the samples, between
-1and1.
See also
kendall_tau_scoreCompute Kendall’s \(\tau\) between label rankings.
Notes
Given a ranking \(y\) of \(m\) labels, where \(y_i\) is the position of label \(i\), let \(a'_{ij}\) be
1if \(y_i \leq y_j\) and-1if \(y_i > y_j\), for \(i \neq j\). The \(\tau_x\) coefficient between the rankings \(y\) and \(\hat{y}\) is\[\tau_x(y, \hat{y}) = \frac{1}{m(m - 1)} \sum_{i \neq j} a'_{ij} \hat{a}'_{ij}.\]Unlike Kendall’s \(\tau_b\), its denominator does not depend on the ties, so a ranking with all its labels tied has a coefficient of
1with itself. It is related to the Kemeny-Snell distance \(d\) by \(\tau_x = 1 - 2 d / (m(m - 1))\).References
[emond_new_2002]E. J. Emond and D. W. Mason, “A new rank correlation coefficient with application to the consensus ranking problem”, Journal of Multi-Criteria Decision Analysis, vol. 11, pp. 17-28, 2002.
Examples
>>> from sklr.metrics import tau_x_score >>> y_true = [[1, 1, 2], [1, 2, 3]] >>> y_pred = [[1, 1, 2], [1, 1, 1]] >>> tau_x_score(y_true, y_pred) 0.5