memModel.plot_tree

In [ ]:
memModel.plot_tree(pic_path: str = "",
                   tree_id: int = 0,
                   feature_names: Union[list, np.ndarray] = [],
                   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 to.
tree_id
int
✓
Unique tree identifier, an integer in the range [0, n_estimators - 1].
feature_names
list / numpy.array
✓
List of the names of each feature.
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

Returns

graphviz.Source : graphviz object.

Example

In [ ]:
from verticapy.learn.memmodel import memModel
model = memModel("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',]})
model.plot_tree()