Loading...

verticapy.machine_learning.memmodel.ensemble.RandomForestRegressor.plot_tree#

RandomForestRegressor.plot_tree(pic_path: str | None = None, tree_id: int = 0, *args, **kwargs) Source#

Draws the input tree. Requires the Graphviz module.

Parameters#

pic_path: str, optional

Absolute path to save the image of the tree.

tree_id: int, optional

Unique tree identifier, an integer in the range [0, n_estimators - 1].

*args, **kwargs: Any, optional

Arguments to pass to the to_graphviz method.

Returns#

graphviz.Source

Graphviz object.

Examples#

Import the required modules and create many BinaryTreeClassifier.

from verticapy.machine_learning.memmodel.tree import BinaryTreeClassifier

model1 = BinaryTreeClassifier(
    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"],
)


model2 = BinaryTreeClassifier(
    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.7, 0.2, 0.1], [0.3, 0.5, 0.2], [0.2, 0.2, 0.6]],
    classes = ["a", "b", "c"],
)


model3 = BinaryTreeClassifier(
    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.4, 0.4, 0.2], [0.2, 0.2, 0.6], [0.2, 0.5, 0.3]],
    classes = ["a", "b", "c"],
)

Let’s create a model.

from verticapy.machine_learning.memmodel.ensemble import RandomForestClassifier

model_rfc = RandomForestClassifier(
    trees = [model1, model2, model3],
    classes = ["a", "b", "c"],
)

Let’s draw the input tree.

model_rfc.plot_tree(tree_id = 0)
../_images/machine_learning_memmodel_ensemble_rfclassifier.png

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.