R_SQUARED

functionsupportedGovernance (policies, tags, data quality)Enterprise+

docs.snowflake.com ↗

Data metric functions

Returns the coefficient of determination (R²) of a column of predicted values against a column of actual values. R² measures the share of the variation in the actual values that the predictions explain. This topic provides the syntax for calling the function directly. To learn how to associate the function with a table or view so it runs at regular intervals, see Associate a DMF. Data Quality Monitoring requires Enterprise Edition. To inquire about upgrading, please contact Snowflake Support.

Syntax

SNOWFLAKE.CORE.R_SQUARED(<query>)

Parameters

NameRequiredDescription
queryrequiredSpecifies a SQL query that projects two columns. The first column contains the predicted values, and the second column contains the actual values.

Returns

The function returns a FLOAT value that is less than or equal to 1: - A value of 1 means that every prediction matches the actual value. - A value of 0 means that the predictions are no better than predicting the average actual value for every row. - A negative value means that the predictions are worse than predicting the average actual value. The function returns NULL if no row has both a predicted and an actual value, or if all of the actual values are the same.

Usage notes

Allowed data types

The two columns projected by the query must have the same data type, which must be one of the following: - FLOAT - NUMBER