Loading...

verticapy.machine_learning.memmodel.ensemble.RandomForestClassifier.predict_sql#

RandomForestClassifier.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 module.

from verticapy.machine_learning.memmodel.naive_bayes import NaiveBayes

Let’s define attributes representing each input feature:

attributes = [
    {
        "type": "gaussian",
        "C": {"mu": 63.9878308300395, "sigma_sq": 7281.87598377196},
        "Q": {"mu": 13.0217386792453, "sigma_sq": 211.626862330204},
        "S": {"mu": 27.6928120412844, "sigma_sq": 1428.57067393938},
    },
    {
        "type": "multinomial",
        "C": 0.771666666666667,
        "Q": 0.910714285714286,
        "S": 0.878216123499142,
    },
    {
        "type": "bernoulli",
        "C": 0.771666666666667,
        "Q": 0.910714285714286,
        "S": 0.878216123499142,
    },
    {
        "type": "categorical",
        "C": {
            "female": 0.407843137254902,
            "male": 0.592156862745098,
        },
        "Q": {
            "female": 0.416666666666667,
            "male": 0.583333333333333,
        },
        "S": {
            "female": 0.406666666666667,
            "male": 0.593333333333333,
        },
    },
]

We also need to provide class names and their prior probabilities.

prior = [0.8, 0.1, 0.1]

classes = ["C", "Q", "S"]

Let’s create a model.

model_nb = NaiveBayes(attributes, prior, classes)

Let’s use the following column names:

cnames = ["age", "pclass", "survived", "sex"]

Get the SQL code needed to deploy the model.

model_nb.predict_sql(cnames)
Out[7]: "CASE WHEN age IS NULL OR pclass IS NULL OR survived IS NULL OR sex IS NULL THEN NULL WHEN 0.010555023401917874 * EXP(- POWER(age - 27.6928120412844, 2) / 2857.14134787876) * POWER(0.878216123499142, pclass) * (CASE WHEN survived THEN 0.878216123499142 ELSE 0.12178387650085798 END) * DECODE(sex, 'female', 0.406666666666667, 'male', 0.593333333333333) * 0.1 >= 0.004675073323276673 * EXP(- POWER(age - 63.9878308300395, 2) / 14563.75196754392) * POWER(0.771666666666667, pclass) * (CASE WHEN survived THEN 0.771666666666667 ELSE 0.22833333333333306 END) * DECODE(sex, 'female', 0.407843137254902, 'male', 0.592156862745098) * 0.8 AND 0.010555023401917874 * EXP(- POWER(age - 27.6928120412844, 2) / 2857.14134787876) * POWER(0.878216123499142, pclass) * (CASE WHEN survived THEN 0.878216123499142 ELSE 0.12178387650085798 END) * DECODE(sex, 'female', 0.406666666666667, 'male', 0.593333333333333) * 0.1 >= 0.027423612860412977 * EXP(- POWER(age - 13.0217386792453, 2) / 423.253724660408) * POWER(0.910714285714286, pclass) * (CASE WHEN survived THEN 0.910714285714286 ELSE 0.08928571428571397 END) * DECODE(sex, 'female', 0.416666666666667, 'male', 0.583333333333333) * 0.1 THEN 'S' WHEN 0.027423612860412977 * EXP(- POWER(age - 13.0217386792453, 2) / 423.253724660408) * POWER(0.910714285714286, pclass) * (CASE WHEN survived THEN 0.910714285714286 ELSE 0.08928571428571397 END) * DECODE(sex, 'female', 0.416666666666667, 'male', 0.583333333333333) * 0.1 >= 0.004675073323276673 * EXP(- POWER(age - 63.9878308300395, 2) / 14563.75196754392) * POWER(0.771666666666667, pclass) * (CASE WHEN survived THEN 0.771666666666667 ELSE 0.22833333333333306 END) * DECODE(sex, 'female', 0.407843137254902, 'male', 0.592156862745098) * 0.8 THEN 'Q' ELSE 'C' 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.