Spark 尚不支持 Kendalls 的等级。但是,如果这对您来说还不算太晚,我找到了以下code ,您可以使用它来计算它。
这里是一个例子:
from operator import add
#sample data in lists
variable_1 = [106, 86, 100, 101, 99, 103, 97, 113, 112, 110]
variable_2 = [7, 0, 27, 50, 28, 29, 20, 12, 6, 17]
#zip sample data and convert to rdd
example_data = zip(variable_1, variable_2)
example_rdd = sc.parallelize(example_data)
#filer out all your null values. Row containing nulls will be removed
example_rdd = example_rdd.filter(lambda x: x is not None).filter(lambda x: x != "")
#take the cartesian product of example data (generate all possible combinations)
all_pairs = example_rdd.cartesian(example_rdd)
#function calculating concorant and disconordant pairs
def calc(pair):
p1, p2 = pair
x1, y1 = p1
x2, y2 = p2
if (x1 == x2) and (y1 == y2):
return ("t", 1) #tie
elif ((x1 > x2) and (y1 > y2)) or ((x1 < x2) and (y1 < y2)):
return ("c", 1) #concordant pair
else:
return ("d", 1) #discordant pair
#rank all pairs and calculate concordant / disconrdant pairs with calc() then return results
results = all_pairs.map(calc)
#aggregate the results
results = results.aggregateByKey(0, add, add)
#count and collect
n = example_rdd.count()
d = {k: v for (k, v) in results.collect()}
# http://en.wikipedia.org/wiki/Kendall_tau_rank_correlation_coefficient
tau = (d["c"] - d["d"]) / (0.5 * n * (n-1))
也许这会有所帮助,或者至少可供将来参考。