pyspark.sql.functions.regr_avgy#
- pyspark.sql.functions.regr_avgy(y, x)[source]#
Aggregate function: returns the average of the dependent variable for non-null pairs in a group, where y is the dependent variable and x is the independent variable.
New in version 3.5.0.
- Parameters
- Returns
Column
the average of the dependent variable for non-null pairs in a group.
Examples
>>> from pyspark.sql import functions as sf >>> x = (sf.col("id") % 3).alias("x") >>> y = (sf.randn(42) + x * 10).alias("y") >>> spark.range(0, 1000, 1, 1).select(x, y).select( ... sf.regr_avgy("y", "x"), sf.avg("y") ... ).show() +-----------------+-----------------+ | regr_avgy(y, x)| avg(y)| +-----------------+-----------------+ |9.980732994136...|9.980732994136...| +-----------------+-----------------+