regr_syy

聚合函数:返回组中非 null 对的REGR_COUNT(y、x) * VAR_POP(y),其中 y 依赖变量是 x 独立变量。

有关相应的 Databricks SQL 函数,请参阅 regr_syy 聚合函数

Syntax

import pyspark.sql.functions as sf

sf.regr_syy(y=<y>, x=<x>)

参数

参数 类型 Description
y pyspark.sql.Columnstr 依赖变量。
x pyspark.sql.Columnstr 独立变量。

退货

pyspark.sql.Column:REGR_COUNT(y, x) * VAR_POP(y) 表示组中的非 null 对。

例子

示例 1:所有对均为非 null。

import pyspark.sql.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_syy("y", "x")).show()
+--------------+
|regr_syy(y, x)|
+--------------+
|           5.0|
+--------------+

示例 2:所有对的 x 值均为 null。

import pyspark.sql.functions as sf
df = spark.sql("SELECT * FROM VALUES (1, null) AS tab(y, x)")
df.select(sf.regr_syy("y", "x")).show()
+--------------+
|regr_syy(y, x)|
+--------------+
|          NULL|
+--------------+

示例 3:所有对的 y 值为 null。

import pyspark.sql.functions as sf
df = spark.sql("SELECT * FROM VALUES (null, 1) AS tab(y, x)")
df.select(sf.regr_syy("y", "x")).show()
+--------------+
|regr_syy(y, x)|
+--------------+
|          NULL|
+--------------+

示例 4:某些对的 x 值为 null。

import pyspark.sql.functions as sf
df = spark.sql("SELECT * FROM VALUES (1, 1), (2, null), (3, 3), (4, 4) AS tab(y, x)")
df.select(sf.regr_syy("y", "x")).show()
+-----------------+
|   regr_syy(y, x)|
+-----------------+
|4.666666666666...|
+-----------------+

示例 5:某些对的 x 或 y 值为 null。

import pyspark.sql.functions as sf
df = spark.sql("SELECT * FROM VALUES (1, 1), (2, null), (null, 3), (4, 4) AS tab(y, x)")
df.select(sf.regr_syy("y", "x")).show()
+--------------+
|regr_syy(y, x)|
+--------------+
|           4.5|
+--------------+