skills/nlp/kendall-tau-ordering-metric/SKILL.md
Evaluates predicted sequence ordering quality using Kendall Tau correlation via efficient O(n log n) inversion counting.
npx skillsauth add wenmin-wu/ds-skills nlp-kendall-tau-ordering-metricInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
For tasks that predict the order of items (cell ordering, passage ranking, document sorting), you need a metric that measures how close the predicted permutation is to the ground truth. Kendall Tau counts the number of pairwise inversions (swapped pairs) and normalizes to [-1, 1]. A score of 1 means perfect order, 0 is random, -1 is fully reversed. Uses bisect-based inversion counting for O(n log n) per sample.
from bisect import bisect
def count_inversions(a):
inversions = 0
sorted_so_far = []
for i, u in enumerate(a):
j = bisect(sorted_so_far, u)
inversions += i - j
sorted_so_far.insert(j, u)
return inversions
def kendall_tau(ground_truth, predictions):
total_inversions = 0
total_2max = 0
for gt, pred in zip(ground_truth, predictions):
ranks = [gt.index(x) for x in pred]
total_inversions += count_inversions(ranks)
n = len(gt)
total_2max += n * (n - 1)
return 1 - 4 * total_inversions / total_2max
1 - 4 * inversions / (n * (n - 1))scipy.stats.kendalltau for single pairs, but this batches efficientlydata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF