lightgbm.plot_tree

lightgbm.plot_tree(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]

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 or LGBMModel instance to be plotted.
  • ax (matplotlib.axes.Axes or None, optional (default=None)) – Target axes instance. If None, new figure and axes will be created.
  • tree_index (int, optional (default=0)) – The index of a target tree to plot.
  • figsize (tuple of 2 elements or None, optional (default=None)) – Figure size.
  • dpi (int or None, optional (default=None)) – Resolution of the figure.
  • show_info (list of strings or None, optional (default=None)) – What information should be shown in nodes. Possible values of list items: ‘split_gain’, ‘internal_value’, ‘internal_count’, ‘internal_weight’, ‘leaf_count’, ‘leaf_weight’, ‘data_percentage’.
  • precision (int or None, optional (default=3)) – Used to restrict the display of floating point values to a certain precision.
  • **kwargs – Other parameters passed to Digraph constructor. Check https://graphviz.readthedocs.io/en/stable/api.html#digraph for the full list of supported parameters.
Returns:

ax – The plot with single tree.

Return type:

matplotlib.axes.Axes