Loading...

verticapy.machine_learning.memmodel.cluster.BisectingKMeans.to_graphviz#

BisectingKMeans.to_graphviz(round_score: int = 2, percent: bool = False, vertical: bool = True, node_style: dict | None = None, edge_style: dict | None = None, leaf_style: dict | None = None) str#

Returns the code for a Graphviz tree.

Parameters#

round_score: int, optional

The number of decimals to round the node’s score to 0 rounds to an integer.

percent: bool, optional

If set to True, the scores are returned as a percent.

vertical: bool, optional

If set to True, the function generates a vertical tree.

node_style: dict, optional

Dictionary of options to customize each node of the tree. For a list of options, see the: Graphviz API .

edge_style: dict, optional

Dictionary of options to customize each arrow of the tree. For a list of options, see the: Graphviz API .

leaf_style: dict, optional

Dictionary of options to customize each leaf of the tree. For a list of options, see the: Graphviz API .

Returns#

str

Graphviz code.

Examples#

Import the required module.

from verticapy.machine_learning.memmodel.cluster import BisectingKMeans

We will use the following attributes:

clusters = [
    [0.5, 0.6],
    [1, 2],
    [100, 200],
    [10, 700],
    [-100, -200],
]


children_left = [1, 3, None, None, None]

children_right = [2, 4, None, None, None]

Let’s create a model.

model_bkm = BisectingKMeans(clusters, children_left, children_right)

Get the model Graphviz representation.

model_bkm.to_graphviz()
Out[6]: 'digraph Tree {\ngraph [rankdir = "LR"];\n0 [label="0", shape="none"]\n0 -> 1 [label=""]\n0 -> 2 [label=""]\n1 [label="1", shape="none"]\n1 -> 3 [label=""]\n1 -> 4 [label=""]\n2 [label="2", shape="none"]\n3 [label="3", shape="none"]\n4 [label="4", shape="none"]\n}'

Note

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