plot_tree(booster, ax=None, tree_index=0, figsize=None, dpi=None, show_info=None, precision=3, orientation='horizontal', **kwargs)¶
Plot specified tree.
Each node in the graph represents a node in the tree.
Non-leaf nodes have labels like
Column_10 <= 875.9, which means “this node splits on the feature named “Column_10”, with threshold 875.9”.
Leaf nodes have labels like
leaf 2: 0.422, which means “this node is a leaf node, and the predicted value for records that fall into this node is 0.422”. The number (
2) is an internal unique identifier and doesn’t have any special meaning.
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.
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.
'split_gain': gain from adding this split to the model
'internal_value': raw predicted value that would be produced by this node if it was a leaf node
'internal_count': number of records from the training data that fall into this non-leaf node
'internal_weight': total weight of all nodes that fall into this non-leaf node
'leaf_count': number of records from the training data that fall into this leaf node
'leaf_weight': total weight (sum of hessian) of all observations that fall into this leaf node
'data_percentage': percentage of training data that fall into this node
precision (int or None, optional (default=3)) – Used to restrict the display of floating point values to a certain precision.
orientation (string, optional (default='horizontal')) – Orientation of the tree. Can be ‘horizontal’ or ‘vertical’.
**kwargs – Other parameters passed to
Digraphconstructor. Check https://graphviz.readthedocs.io/en/stable/api.html#digraph for the full list of supported parameters.
ax – The plot with single tree.
- Return type