計算資料框中兩欄的相關性,作為雙重值。 目前只支援 Pearson 相關係數。
DataFrame.corr 兩者 DataFrameStatFunctions.corr 是彼此的別名。
語法
corr(col1: str, col2: str, method: Optional[str] = None)
參數
| 參數 | 類型 | 說明 |
|---|---|---|
col1 |
str | 第一欄的名字。 |
col2 |
str | 第二欄的名字。 |
method |
力量,選用 | 相關性方法。 目前只支援「Pearson」。 |
退貨
浮點:兩欄皮爾森相關係數。
Examples
df = spark.createDataFrame([(1, 12), (10, 1), (19, 8)], ["c1", "c2"])
df.corr("c1", "c2")
# -0.3592106040535498
df = spark.createDataFrame([(11, 12), (10, 11), (9, 10)], ["small", "bigger"])
df.corr("small", "bigger")
# 1.0