Package nltk :: Package metrics :: Module spearman
[hide private]
[frames] | no frames]

Module spearman

source code

Tools for comparing ranked lists.

Functions [hide private]
 
_rank_dists(ranks1, ranks2)
Finds the difference between the values in ranks1 and ranks2 for keys present in both dicts.
source code
 
spearman_correlation(ranks1, ranks2)
Returns the Spearman correlation coefficient for two rankings, which should be dicts or sequences of (key, rank).
source code
 
ranks_from_sequence(seq)
Given a sequence, yields each element with an increasing rank, suitable for use as an argument to spearman_correlation.
source code
 
ranks_from_scores(scores, rank_gap=1e-15)
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.
source code
Function Details [hide private]

_rank_dists(ranks1, ranks2)

source code 

Finds the difference between the values in ranks1 and ranks2 for keys present in both dicts. If the arguments are not dicts, they are converted from (key, rank) sequences.

spearman_correlation(ranks1, ranks2)

source code 

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).

ranks_from_scores(scores, rank_gap=1e-15)

source code 

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.