我在看文件 Statistics.corr
在Pypark中:https://spark.apache.org/docs/1.1.0/api/python/pyspark.mllib.stat.statistics-class.html#corr.
为什么这里的相关性会导致 NaN
?
>>> rdd = sc.parallelize([Vectors.dense([1, 0, 0, -2]), Vectors.dense([4, 5, 0, 3]),
... Vectors.dense([6, 7, 0, 8]), Vectors.dense([9, 0, 0, 1])])
>>> pearsonCorr = Statistics.corr(rdd)
>>> print str(pearsonCorr).replace('nan', 'NaN')
[[ 1. 0.05564149 NaN 0.40047142]
[ 0.05564149 1. NaN 0.91359586]
[ NaN NaN 1. NaN]
[ 0.40047142 0.91359586 NaN 1. ]]
1条答案
按热度按时间vcudknz31#
皮尔逊相关系数的定义如下:
因为第二列的标准差(
[0, 0, 0, 0]
)等于0,整个方程的结果为nan。