Loading...

verticapy.machine_learning.memmodel.tree.BinaryTreeRegressor.predict_sql

BinaryTreeRegressor.predict_sql(X: Annotated[list | ndarray, 'Array Like Structure']) 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 module.

from verticapy.machine_learning.memmodel.tree import BinaryTreeClassifier

We will use the following attributes:

# Different Attributes
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,
    [0.8, 0.1, 0.1],
    [0.1, 0.8, 0.1],
    [0.2, 0.2, 0.6],
]


classes = ["a", "b", "c"]

Let’s create a model.

# Building the Model
model_btc = BinaryTreeClassifier(
    children_left = children_left,
    children_right = children_right,
    feature = feature,
    threshold = threshold,
    value = value,
    classes = classes,
)

Let’s use the following column names:

cnames = ["sex", "fare"]

Get the SQL code needed to deploy the model.

model_btc.predict_sql(cnames)
Out[66]: "(CASE WHEN sex = 'female' THEN (CASE WHEN fare < 30 THEN 'b' ELSE 'c' END) ELSE 'a' END)"

Important

For this example, a specific model is utilized, and it may not correspond exactly to the model you are working with. To see a comprehensive example specific to your class of interest, please refer to that particular class.