MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / plot_tree

Function plot_tree

python-package/lightgbmmt/plotting.py:548–617  ·  view source on GitHub ↗

Plot specified tree. .. note:: It is preferable to use ``create_tree_digraph()`` because of its lossless quality and returned objects can be also rendered and displayed directly inside a Jupyter notebook. Parameters ---------- booster : Booster or LGBMModel

(booster, ax=None, tree_index=0, figsize=None, dpi=None,
              old_graph_attr=None, old_node_attr=None, old_edge_attr=None,
              show_info=None, precision=3, **kwargs)

Source from the content-addressed store, hash-verified

546
547
548def plot_tree(booster, ax=None, tree_index=0, figsize=None, dpi=None,
549 old_graph_attr=None, old_node_attr=None, old_edge_attr=None,
550 show_info=None, precision=3, **kwargs):
551 """Plot specified tree.
552
553 .. note::
554
555 It is preferable to use ``create_tree_digraph()`` because of its lossless quality
556 and returned objects can be also rendered and displayed directly inside a Jupyter notebook.
557
558 Parameters
559 ----------
560 booster : Booster or LGBMModel
561 Booster or LGBMModel instance to be plotted.
562 ax : matplotlib.axes.Axes or None, optional (default=None)
563 Target axes instance.
564 If None, new figure and axes will be created.
565 tree_index : int, optional (default=0)
566 The index of a target tree to plot.
567 figsize : tuple of 2 elements or None, optional (default=None)
568 Figure size.
569 dpi : int or None, optional (default=None)
570 Resolution of the figure.
571 show_info : list of strings or None, optional (default=None)
572 What information should be shown in nodes.
573 Possible values of list items:
574 'split_gain', 'internal_value', 'internal_count', 'internal_weight',
575 'leaf_count', 'leaf_weight', 'data_percentage'.
576 precision : int or None, optional (default=3)
577 Used to restrict the display of floating point values to a certain precision.
578 **kwargs
579 Other parameters passed to ``Digraph`` constructor.
580 Check https://graphviz.readthedocs.io/en/stable/api.html#digraph for the full list of supported parameters.
581
582 Returns
583 -------
584 ax : matplotlib.axes.Axes
585 The plot with single tree.
586 """
587 if MATPLOTLIB_INSTALLED:
588 import matplotlib.pyplot as plt
589 import matplotlib.image as image
590 else:
591 raise ImportError('You must install matplotlib to plot tree.')
592
593 for param_name in ['old_graph_attr', 'old_node_attr', 'old_edge_attr']:
594 param = locals().get(param_name)
595 if param is not None:
596 warnings.warn('{0} parameter is deprecated and will be removed in 2.4 version.\n'
597 'Please use **kwargs to pass {1} parameter.'.format(param_name, param_name[4:]),
598 LGBMDeprecationWarning)
599 if param_name[4:] not in kwargs:
600 kwargs[param_name[4:]] = param
601
602 if ax is None:
603 if figsize is not None:
604 _check_not_tuple_of_2_elements(figsize, 'figsize')
605 _, ax = plt.subplots(1, 1, figsize=figsize, dpi=dpi)

Callers

nothing calls this directly

Calls 6

create_tree_digraphFunction · 0.85
formatMethod · 0.80
pipeMethod · 0.80
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected