Loading...

verticapy.machine_learning.memmodel.cluster.BisectingKMeans.predict_sql#

BisectingKMeans.predict_sql(X: list | ndarray) str#

Returns the SQL code needed to deploy the BisectingKMeans model using its attributes.

Parameters#

X: ArrayLike

The names or values of the input predictors.

Returns#

str

SQL code.

Examples#

Import the required module.

from verticapy.machine_learning.memmodel.cluster import BisectingKMeans

We will use the following attributes:

clusters = [
    [0.5, 0.6],
    [1, 2],
    [100, 200],
    [10, 700],
    [-100, -200],
]


children_left = [1, 3, None, None, None]

children_right = [2, 4, None, None, None]

Let’s create a model.

model_bkm = BisectingKMeans(clusters, children_left, children_right)

Let’s use the following column names:

cnames = ['col1', 'col2']

Get the SQL code needed to deploy the model.

model_bkm.predict_sql(cnames)
Out[7]: '(CASE WHEN col1 IS NULL OR col2 IS NULL THEN NULL ELSE (CASE WHEN POWER(POWER(col1 - 1.0, 2) + POWER(col2 - 2.0, 2), 1/2) < POWER(POWER(col1 - 100.0, 2) + POWER(col2 - 200.0, 2), 1/2) THEN (CASE WHEN POWER(POWER(col1 - 10.0, 2) + POWER(col2 - 700.0, 2), 1/2) < POWER(POWER(col1 - -100.0, 2) + POWER(col2 - -200.0, 2), 1/2) THEN 3 ELSE 4 END) ELSE 2 END) END)'

Note

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