Loading...

verticapy.machine_learning.memmodel.ensemble.IsolationForest.predict#

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

Predicts using the IsolationForest model.

Parameters#

X: ArrayLike

The data on which to make the prediction.

Returns#

numpy.array

Predicted values.

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])

Create a dataset.

data = [["male", 100], ["female", 20], ["female", 50]]

Compute the predictions.

model_isf.predict(data)
Out[8]: array([0.6213801 , 0.70052979, 0.43580485])

Note

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