snowflake.snowpark.functions.regr_slope

snowflake.snowpark.functions.regr_slope(y: Union[Column, str], x: Union[Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.29.1/snowpark-python/src/snowflake/snowpark/functions.py#L11246-L11262)

Returns the slope of the linear regression line for non-null pairs in a group. It is computed for non-null pairs using the following formula: COVAR_POP(x,y) / VAR_POP(x), where x is the independent variable and y is the dependent variable.

Example:

>>> df = session.create_dataframe([[10, 11], [20, 22], [25, None], [30, 35]], schema=["v", "v2"])
>>> df = df.group_by("v").agg(regr_slope(df["v2"], df["v"]).alias("regr_slope"))
>>> df.collect()
[Row(V=10, REGR_SLOPE=None), Row(V=20, REGR_SLOPE=None), Row(V=25, REGR_SLOPE=None), Row(V=30, REGR_SLOPE=None)]
Copy
Language: English