nltk.metrics.spearman module¶
Tools for comparing ranked lists.
- nltk.metrics.spearman.ranks_from_scores(scores, rank_gap=1e-15)[source]¶
Given a sequence of (key, score) tuples, yields each key with an increasing rank, tying with previous key’s rank if the difference between their scores is less than rank_gap. Suitable for use as an argument to
spearman_correlation
.
- nltk.metrics.spearman.ranks_from_sequence(seq)[source]¶
Given a sequence, yields each element with an increasing rank, suitable for use as an argument to
spearman_correlation
.
- nltk.metrics.spearman.spearman_correlation(ranks1, ranks2)[source]¶
Returns the Spearman correlation coefficient for two rankings, which should be dicts or sequences of (key, rank). The coefficient ranges from -1.0 (ranks are opposite) to 1.0 (ranks are identical), and is only calculated for keys in both rankings (for meaningful results, remove keys present in only one list before ranking).