The ML.ROBUST_SCALER function

This document describes the ML.ROBUST_SCALER function, which lets you scale a numerical expression by using statistics that are robust to outliers. The function performs the scaling by removing the median and scaling the data according to the quantile range.

When used in the TRANSFORM clause, the median and quantile range calculated during training are automatically used in prediction.

Syntax

ML.ROBUST_SCALER(numerical_expression [, quantile_range] [, with_median] [, with_quantile_range]) OVER()

Arguments

ML.ROBUST_SCALER takes the following arguments:

Output

ML.ROBUST_SCALER returns a FLOAT64 value that represents the scaled numerical expression.

Example

The following example centers a set of numerical expressions and then scales it to the range [25, 75]:

SELECT f, ML.ROBUST_SCALER(f) OVER () AS output
FROM
  UNNEST([NULL, -3, 1, 2, 3, 4, 5]) AS f
ORDER BY f;

The output looks similar to the following:

+------+---------------------+
|  f   |       output        |
+------+---------------------+
| NULL |                NULL |
|   -3 | -1.6666666666666667 |
|    1 | -0.3333333333333333 |
|    2 |                 0.0 |
|    3 |  0.3333333333333333 |
|    4 |  0.6666666666666666 |
|    5 |                 1.0 |
+------+---------------------+

What's next