Model.plot_tree

In [ ]:
Model.plot_tree(pic_path: str = "",
                tree_id: int = 0,
                classes_color: list = [],
                round_pred: int = 2,
                percent: bool = False,
                vertical: bool = True,
                node_style: dict = {},
                arrow_style: dict = {},
                leaf_style: dict = {},)

Draws the input tree. Requires the graphviz module.

Parameters

Name Type Optional Description
pic_path
str
Absolute path to save the image of the tree.
tree_id
int
Unique tree identifier. It is an integer between 0 and n_estimators - 1
classes_color
list
Colors that represent the different classes.
round_pred
int
The number of decimals to round the prediction to. 0 rounds to an integer.
percent
bool
If set to True, the probabilities are returned as a percent.
vertical
bool
If set to True, the function generates a vertical tree.
node_style
dict
Dictionary of options to customize each node of the tree. For a list of options, see the Graphviz API: https://graphviz.org/doc/info/attrs.html
arrow_style
dict
Dictionary of options to customize each arrow of the tree. For a list of options, see the Graphviz API: https://graphviz.org/doc/info/attrs.html
leaf_style
dict
Dictionary of options to customize each leaf of the tree. For a list of options, see the Graphviz API: https://graphviz.org/doc/info/attrs.html

Example

In [ ]:
from verticapy.learn.ensemble import RandomForestClassifier
model = RandomForestClassifier(name = "public.RF_iris",
                               n_estimators = 20,
                               max_features = "auto",
                               max_leaf_nodes = 32, 
                               sample = 0.7,
                               max_depth = 3,
                               min_samples_leaf = 5,
                               min_info_gain = 0.0,
                               nbins = 32)
model.fit("public.iris", 
          ["PetalLengthCm", "PetalWidthCm"], 
          "Species")
model.plot_tree(tree_id = 3)