APPLY_ONE_HOT_ENCODER
A user-defined transform function (UDTF) that loads the one hot encoder model and writes out a table that contains the encoded columns.
Syntax
APPLY_ONE_HOT_ENCODER( input‑columns USING PARAMETERS model_name='model‑name' [, drop_first='is‑first'] [, ignore_null='ignore'] [, separator='separator‑character'] [, column_naming='name‑output'] [, null_column_name='null‑column‑name'] )
Arguments
input‑columns | Comma-separated list of columns to use from the input relation, or asterisk (*) to select all columns. |
Parameter Settings
Parameter name | Set to… |
---|---|
model_name
|
Name of the model (case-insensitive) , stores the categories and their corresponding levels. |
drop_first
|
Boolean value, one of the following:
|
ignore_null
|
Boolean value, one of the following:
|
separator
|
The character that separates the input variable name and the indicator variable level in the output table.To avoid using any separator, set this parameter to null value. Default: Underscore ( |
column_naming
|
Appends categorical levels to column names according to the specified method:
The following column naming rules apply if
|
null_column_name
|
The string used in naming the indicator column for null values, used only if Default: |
Examples
=> SELECT APPLY_ONE_HOT_ENCODER(cyl USING PARAMETERS model_name='one_hot_encoder_model', drop_first='true', ignore_null='false') FROM mtcars; cyl | cyl_1 | cyl_2 ----+-------+------- 8 | 0 | 1 4 | 0 | 0 4 | 0 | 0 8 | 0 | 1 8 | 0 | 1 8 | 0 | 1 4 | 0 | 0 8 | 0 | 1 8 | 0 | 1 4 | 0 | 0 8 | 0 | 1 6 | 1 | 0 4 | 0 | 0 4 | 0 | 0 6 | 1 | 0 6 | 1 | 0 8 | 0 | 1 8 | 0 | 1 4 | 0 | 0 4 | 0 | 0 6 | 1 | 0 8 | 0 | 1 8 | 0 | 1 6 | 1 | 0 4 | 0 | 0 8 | 0 | 1 8 | 0 | 1 8 | 0 | 1 6 | 1 | 0 6 | 1 | 0 4 | 0 | 0 4 | 0 | 0 (32 rows)
See Also