memModel.to_graphviz

In [ ]:
memModel.to_graphviz(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 = {},)

Returns the code for a Graphviz tree.

Parameters

Name Type Optional Description
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 [11]:
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.to_graphviz()
Out[11]:
'digraph Tree{\n0 [label="X0", shape="box", style="filled"]\n0 -> 1 [label="= female"]\n0 -> 2 [label="!= female"]\n1 [label="X1", shape="box", style="filled"]\n1 -> 3 [label="<= 30"]\n1 -> 4 [label="> 30"]\n2 [label=<<table border="0" cellspacing="0"> <tr><td port="port1" border="1" bgcolor="#87cefa"><b> prediction: a </b></td></tr><tr><td port="port0" border="1" align="left"> prob(a): 0.8 </td></tr><tr><td port="port1" border="1" align="left"> prob(b): 0.1 </td></tr><tr><td port="port2" border="1" align="left"> prob(c): 0.1 </td></tr></table>>, shape="none"]\n3 [label=<<table border="0" cellspacing="0"> <tr><td port="port1" border="1" bgcolor="#efc5b5"><b> prediction: b </b></td></tr><tr><td port="port0" border="1" align="left"> prob(a): 0.1 </td></tr><tr><td port="port1" border="1" align="left"> prob(b): 0.8 </td></tr><tr><td port="port2" border="1" align="left"> prob(c): 0.1 </td></tr></table>>, shape="none"]\n4 [label=<<table border="0" cellspacing="0"> <tr><td port="port1" border="1" bgcolor="#d4ede3"><b> prediction: c </b></td></tr><tr><td port="port0" border="1" align="left"> prob(a): 0.2 </td></tr><tr><td port="port1" border="1" align="left"> prob(b): 0.2 </td></tr><tr><td port="port2" border="1" align="left"> prob(c): 0.6 </td></tr></table>>, shape="none"]\n}'