The ML.MAX_ABS_SCALER function

This document describes the ML.MAX_ABS_SCALER function, which lets you scale a numerical expression to the range [-1, 1] by dividing with the maximum absolute value. It doesn't shift or center the data, and so doesn't destroy any sparsity.

When used in the TRANSFORM clause, the maximum absolute value calculated during training is automatically used in prediction.

Syntax

ML.MAX_ABS_SCALER(numerical_expression) OVER()

Arguments

ML.MAX_ABS_SCALER takes the following argument:

  • numerical_expression: the numerical expression to scale.

Output

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

Example

The following example scales a set of numerical expressions to have values between -1 and 1:

SELECT f, ML.MAX_ABS_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 |   -0.6 |
|    1 |    0.2 |
|    2 |    0.4 |
|    3 |    0.6 |
|    4 |    0.8 |
|    5 |    1.0 |
+------+--------+

What's next