计算一个双精度值的两列 DataFrame 的相关性。 目前仅支持 Pearson 相关系数。
DataFrame.corr 是 DataFrameStatFunctions.corr 彼此的别名。
Syntax
corr(col1, col2, method=None)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
col1 |
str | 第一列的名称。 |
col2 |
str | 第二列的名称。 |
method |
str,可选 | 相关方法。 当前仅支持 "pearson"。 |
退货
float
示例
df = spark.createDataFrame([(1, 12), (10, 1), (19, 8)], ["c1", "c2"])
df.stat.corr("c1", "c2")
# -0.3592106040535498
df = spark.createDataFrame([(11, 12), (10, 11), (9, 10)], ["small", "bigger"])
df.stat.corr("small", "bigger")
# 1.0