Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
聚合函数:返回组中非 null 对的线性回归线的斜率,其中 y 是依赖变量,也是 x 独立变量。
Syntax
from pyspark.sql import functions as sf
sf.regr_slope(y, x)
参数
| 参数 | 类型 | Description |
|---|---|---|
y |
pyspark.sql.Column 或 str |
依赖变量。 |
x |
pyspark.sql.Column 或 str |
独立变量。 |
退货
pyspark.sql.Column:组中非 null 对的线性回归线的斜率。
例子
示例 1:所有对均为非 null
from pyspark.sql import functions as sf
df = spark.sql("SELECT * FROM VALUES (1, 1), (2, 2), (3, 3), (4, 4) AS tab(y, x)")
df.select(sf.regr_slope("y", "x")).show()
+----------------+
|regr_slope(y, x)|
+----------------+
| 1.0|
+----------------+
示例 2:所有对的 x 值均为 null
from pyspark.sql import functions as sf
df = spark.sql("SELECT * FROM VALUES (1, null) AS tab(y, x)")
df.select(sf.regr_slope("y", "x")).show()
+----------------+
|regr_slope(y, x)|
+----------------+
| NULL|
+----------------+
示例 3:所有对的 y 值为 null
from pyspark.sql import functions as sf
df = spark.sql("SELECT * FROM VALUES (null, 1) AS tab(y, x)")
df.select(sf.regr_slope("y", "x")).show()
+----------------+
|regr_slope(y, x)|
+----------------+
| NULL|
+----------------+