メインコンテンツまでスキップ

regr_intercept

集計関数: グループ内の非 NULL ペアの単変量線形回帰直線の切片を返します。ここで、 yは従属変数、 xは独立変数です。

対応する Databricks SQL 関数については、 regr_intercept集計関数を参照してください。

構文

Python
import pyspark.sql.functions as sf

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

パラメーター

パラメーター

Type

説明

y

pyspark.sql.Column または str

従属変数。

x

pyspark.sql.Column または str

独立変数。

戻り値

pyspark.sql.Column: グループ内の非ヌルペアの単変量線形回帰直線の切片。

例 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_intercept("y", "x")).show()
Output
+--------------------+
|regr_intercept(y, x)|
+--------------------+
| 0.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_intercept("y", "x")).show()
Output
+--------------------+
|regr_intercept(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_intercept("y", "x")).show()
Output
+--------------------+
|regr_intercept(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_intercept("y", "x")).show()
Output
+--------------------+
|regr_intercept(y, x)|
+--------------------+
| 0.0|
+--------------------+

例 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_intercept("y", "x")).show()
Output
+--------------------+
|regr_intercept(y, x)|
+--------------------+
| 0.0|
+--------------------+