Loading...

verticapy.machine_learning.memmodel.ensemble.IsolationForest.predict_sql#

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

Returns the SQL code needed to deploy the model.

Parameters#

X: ArrayLike

The names or values of the input predictors.

Returns#

str

SQL code.

Examples#

Import the required modules and create many BinaryTreeAnomaly.

from verticapy.machine_learning.memmodel.tree import BinaryTreeAnomaly

model1 = BinaryTreeAnomaly(
    children_left = [1, 3, None, None, None],
    children_right = [2, 4, None, None, None],
    feature = [0, 1, None, None, None],
    threshold = ["female", 30, None, None, None],
    value = [None, None, [2, 10], [3, 4], [7, 8]],
    psy = 100,
)


model2 = BinaryTreeAnomaly(
    children_left = [1, 3, None, None, None],
    children_right = [2, 4, None, None, None],
    feature = [0, 1, None, None, None],
    threshold = ["female", 30, None, None, None],
    value = [None, None, [1, 11], [2, 5], [5, 10]],
    psy = 100,
)


model3 = BinaryTreeAnomaly(
    children_left = [1, 3, None, None, None],
    children_right = [2, 4, None, None, None],
    feature = [0, 1, None, None, None],
    threshold = ["female", 30, None, None, None],
    value = [None, None, [3, 9], [1, 6], [8, 7]],
    psy = 100,
)

Let’s create a model.

from verticapy.machine_learning.memmodel.ensemble import IsolationForest

model_isf = IsolationForest(trees = [model1, model2, model3])

Let’s use the following column names:

cnames = ["sex", "fare"]

Get the SQL code needed to deploy the model.

model_isf.predict_sql(cnames)
Out[8]: "POWER(2, - (((CASE WHEN sex = 'female' THEN (CASE WHEN fare < 30 THEN 0.5800175392069298 ELSE 1.2309212867903394 END) ELSE 0.6872811212546747 END) + (CASE WHEN sex = 'female' THEN (CASE WHEN fare < 30 THEN 0.5172970982941328 ELSE 1.0459324046363703 END) ELSE 0.5907488387580265 END) + (CASE WHEN sex = 'female' THEN (CASE WHEN fare < 30 THEN 0.44313045601876805 ELSE 1.3178838132835962 END) ELSE 0.7813262006226015 END)) / 3))"

Note

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