計算 a DataFrame 的兩欄相關係數為雙重值。 目前只支援 Pearson 相關係數。
DataFrame.corr 兩者 DataFrameStatFunctions.corr 是彼此的別名。
語法
corr(col1, col2, method=None)
參數
| 參數 | 類型 | 說明 |
|---|---|---|
col1 |
str | 第一欄的名字。 |
col2 |
str | 第二欄的名字。 |
method |
力量,選用 | 相關性方法。 目前僅支援 "pearson"。 |
退貨
float
Examples
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