Loading...

vastorbit.machine_learning.memmodel.tree.BinaryTreeClassifier.to_graphviz

BinaryTreeClassifier.to_graphviz(feature_names: Annotated[list | ndarray, 'Array Like Structure'] | None = None, classes_color: Annotated[list | ndarray, 'Array Like Structure'] | None = None, round_pred: 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:
  • feature_names (ArrayLike, optional) – List of the names of each feature.

  • classes_color (ArrayLike, optional) – Colors that represent the different classes.

  • round_pred (int, optional) – The number of decimals to round the prediction to. 0 rounds to an integer.

  • percent (bool, optional) – If set to True, the probabilities are returned as percents.

  • 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 edge 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:

Graphviz code.

Return type:

str

Examples

Import the required module.

from vastorbit.machine_learning.memmodel.tree import BinaryTreeClassifier

We will use the following attributes:

# Different Attributes
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"]

Let’s create a model.

# Building the Model
model_btc = BinaryTreeClassifier(
    children_left = children_left,
    children_right = children_right,
    feature = feature,
    threshold = threshold,
    value = value,
    classes = classes,
)

Get the model Graphviz representation.

model_btc.to_graphviz()

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.