MAPE
functionsupportedGovernance (policies, tags, data quality)Enterprise+Returns the mean absolute percentage error (MAPE) between a column of predicted values and a column of actual values. MAPE is the average size of an error, expressed as a percentage of the actual value. 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.MAPE(<query>)
Parameters
| Name | Required | Description |
|---|---|---|
query | required | Specifies 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 greater than or equal to 0. A value of 0 means that every prediction matches the actual value. The value has no upper bound: a prediction that is three times the actual value contributes an error of 200 percent. The function returns NULL if no row has both a predicted value and a non-zero actual value.
Usage notes
- The function computes 100 * AVG(ABS((actual - predicted) / actual)).
- The order of the columns matters. The first column is the predicted value and the second is the actual value. When you associate the function with a table or view, specify the columns in the same order: ON (predicted_column, actual_column).
- Rows in which either value is NULL are ignored.
- You can’t mix data types. For example, you can’t use the function on a NUMBER column of predictions and a FLOAT column of actual values.
- Rows in which the actual value is 0 are ignored, because the percentage error is undefined for them. If many actual values are 0 or close to 0, use MAE or RMSE instead.
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