regr_sxy
集計関数: グループ内の null 以外のペアに対して REGR_COUNT(y, x) * COVAR_POP(y, x) を返します。ここで、 yは従属変数、 xは独立変数です。
対応する Databricks SQL 関数については、 regr_sxy集計関数を参照してください。
構文
Python
import pyspark.sql.functions as sf
sf.regr_sxy(y=<y>, x=<x>)
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
|
| 従属変数。 |
|
| 独立変数。 |
戻り値
pyspark.sql.Column: グループ内の非ヌルペアの場合、REGR_COUNT(y, x) * COVAR_POP(y, x)。
例
例 1 : すべてのペアは null ではありません。
Python
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_sxy("y", "x")).show()
Output
+--------------+
|regr_sxy(y, x)|
+--------------+
| 5.0|
+--------------+
例 2 : すべてのペアの x 値は null です。
Python
import pyspark.sql.functions as sf
df = spark.sql("SELECT * FROM VALUES (1, null) AS tab(y, x)")
df.select(sf.regr_sxy("y", "x")).show()
Output
+--------------+
|regr_sxy(y, x)|
+--------------+
| NULL|
+--------------+
例 3 : すべてのペアの y 値は null です。
Python
import pyspark.sql.functions as sf
df = spark.sql("SELECT * FROM VALUES (null, 1) AS tab(y, x)")
df.select(sf.regr_sxy("y", "x")).show()
Output
+--------------+
|regr_sxy(y, x)|
+--------------+
| NULL|
+--------------+
例 4 : 一部のペアの x 値は null です。
Python
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_sxy("y", "x")).show()
Output
+-----------------+
| regr_sxy(y, x)|
+-----------------+
|4.666666666666...|
+-----------------+
例 5 : 一部のペアの x または y 値が null です。
Python
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_sxy("y", "x")).show()
Output
+--------------+
|regr_sxy(y, x)|
+--------------+
| 4.5|
+--------------+