Loading...

verticapy.machine_learning.memmodel.ensemble.RandomForestClassifier.predict#

RandomForestClassifier.predict(X: list | ndarray) ndarray#

Predicts using the input matrix.

Parameters#

X: ArrayLike

The data on which to make the prediction.

Returns#

numpy.array

Predicted values.

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)

Create a dataset.

data = [
    [40.0, 1, True, "male"],
    [60.0, 3, True, "male"],
    [15.0, 2, False, "female"],
]

Compute the predictions.

model_nb.predict(data)
Out[7]: array(['C', 'C', 'Q'], dtype='<U1')

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.