Loading...

verticapy.machine_learning.memmodel.preprocessing.OneHotEncoder.transform_sql

OneHotEncoder.transform_sql(X: Annotated[list | ndarray, 'Array Like Structure']) list[str]

Transforms and returns the SQL needed to deploy the Scaler.

Parameters

X: ArrayLike

The names or values of the input predictors.

Returns

list

SQL code.

Examples

Import the required module.

from verticapy.machine_learning.memmodel.preprocessing import OneHotEncoder

Let’s create a model.

model_ohe = OneHotEncoder(
    categories = [["male", "female"], [1, 2, 3]],
    drop_first = False,
    column_naming = None,
)

Let’s use the following column names:

cnames = ['sex', 'pclass']

Get the SQL code needed to deploy the model.

model_ohe.transform_sql(cnames)
Out[4]: 
[["(CASE WHEN sex = 'male' THEN 1 ELSE 0 END)",
  "(CASE WHEN sex = 'female' THEN 1 ELSE 0 END)"],
 ['(CASE WHEN pclass = 1 THEN 1 ELSE 0 END)',
  '(CASE WHEN pclass = 2 THEN 1 ELSE 0 END)',
  '(CASE WHEN pclass = 3 THEN 1 ELSE 0 END)']]

Note

Refer to OneHotEncoder for more information about the different methods and usages.