The ML.ROBUST_SCALER function
This document describes theML.ROBUST_SCALER function, which lets you scale anumerical expression by using statistics that are robust to outliers. Thefunction performs the scaling by removing themedian and scalingthe data according to thequantilerange.
When used in theTRANSFORM clause,the median and quantile range calculated during training are automaticallyused in prediction.
You can use this function with models that supportmanual feature preprocessing. For moreinformation, see the following documents:
Syntax
ML.ROBUST_SCALER(numerical_expression [, quantile_range] [, with_median] [, with_quantile_range]) OVER()
Arguments
ML.ROBUST_SCALER takes the following arguments:
numerical_expression: thenumericalexpression to scale.quantile_range: an array of twoINT64elements that specifiesthe quantile range. The first element provides the lower boundary of therange. It must be greater than0. The second element provides the upperboundary of the range. It must be greater than the first element but lessthan100. The default value is[25, 75].with_median: aBOOLvalue that specifies whether the datais centered. IfTRUE, the function centers the data by removing themedian before scaling. The default value isTRUE.with_quantile_range: aBOOLvalue that specifies whether thedata is scaled to the quantile range. IfTRUE, the data is scaled. Thedefault value isTRUE.
Output
ML.ROBUST_SCALER returns aFLOAT64 value that represents the scalednumerical expression.
Example
The following example centers a set of numerical expressions and thenscales it to the range[25, 75]:
SELECTf,ML.ROBUST_SCALER(f)OVER()ASoutputFROMUNNEST([NULL,-3,1,2,3,4,5])ASfORDERBYf;
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
- For information about feature preprocessing, seeFeature preprocessing overview.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.