Loading...

verticapy.machine_learning.memmodel.cluster.KPrototypes.transform_sql#

KPrototypes.transform_sql(X: list | ndarray) list[str]#

Transforms and returns the SQL distance to each cluster.

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.cluster import KPrototypes

We will use the following attributes:

clusters = [
    [0.5, 'high'],
    [1, 'low'],
    [100, 'high'],
]


p = 2

gamma = 1.0

is_categorical = [0, 1]

Let’s create a model.

model_kp = KPrototypes(clusters, p, gamma, is_categorical)

Let’s use the following column names:

cnames = ['col1', 'col2']

Get the SQL code needed to deploy the model.

model_kp.transform_sql(cnames)
Out[8]: 
["POWER(POWER(col1 - 0.5, 2), 1 / 2) + 1.0 * (ABS((col2 = 'high')::int - 1))",
 "POWER(POWER(col1 - 1, 2), 1 / 2) + 1.0 * (ABS((col2 = 'low')::int - 1))",
 "POWER(POWER(col1 - 100, 2), 1 / 2) + 1.0 * (ABS((col2 = 'high')::int - 1))"]

Note

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