snowflake.snowpark.functions.regr_r2¶

snowflake.snowpark.functions.regr_r2(y: Union[Column, str], x: Union[Column, str]) → Column[source]¶

Returns the coefficient of determination for non-null pairs in a group. It is computed for non-null pairs using the following formula: NULL if VAR_POP(x) = 0, else 1 if VAR_POP(y) = 0 and VAR_POP(x) <> 0, else POWER(CORR(y,x), 2). 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.groupBy("v").agg(regr_r2(col("v"), col("v2")).alias("regr_r2")).collect()
[Row(V=10, REGR_R2=None), Row(V=20, REGR_R2=None), Row(V=25, REGR_R2=None), Row(V=30, REGR_R2=None)]
Copy