Medial Code Documentation
Loading...
Searching...
No Matches
Functions
lightgbm.plotting Namespace Reference

Functions

 _check_not_tuple_of_2_elements (obj, obj_name='obj')
 
 _float2str (value, precision=None)
 
 plot_importance (booster, ax=None, height=0.2, xlim=None, ylim=None, title='Feature importance', xlabel='Feature importance', ylabel='Features', importance_type='split', max_num_features=None, ignore_zero=True, figsize=None, grid=True, precision=None, **kwargs)
 
 plot_metric (booster, metric=None, dataset_names=None, ax=None, xlim=None, ylim=None, title='Metric during training', xlabel='Iterations', ylabel='auto', figsize=None, grid=True)
 
 _to_graphviz (tree_info, show_info, feature_names, precision=None, **kwargs)
 
 create_tree_digraph (booster, tree_index=0, show_info=None, precision=None, old_name=None, old_comment=None, old_filename=None, old_directory=None, old_format=None, old_engine=None, old_encoding=None, old_graph_attr=None, old_node_attr=None, old_edge_attr=None, old_body=None, old_strict=False, **kwargs)
 
 plot_tree (booster, ax=None, tree_index=0, figsize=None, old_graph_attr=None, old_node_attr=None, old_edge_attr=None, show_info=None, precision=None, **kwargs)
 

Detailed Description

Plotting library.

Function Documentation

◆ _check_not_tuple_of_2_elements()

lightgbm.plotting._check_not_tuple_of_2_elements (   obj,
  obj_name = 'obj' 
)
protected
Check object is not tuple or does not have 2 elements.

◆ _to_graphviz()

lightgbm.plotting._to_graphviz (   tree_info,
  show_info,
  feature_names,
  precision = None,
**  kwargs 
)
protected
Convert specified tree to graphviz instance.

See:
  - https://graphviz.readthedocs.io/en/stable/api.html#digraph

◆ create_tree_digraph()

lightgbm.plotting.create_tree_digraph (   booster,
  tree_index = 0,
  show_info = None,
  precision = None,
  old_name = None,
  old_comment = None,
  old_filename = None,
  old_directory = None,
  old_format = None,
  old_engine = None,
  old_encoding = None,
  old_graph_attr = None,
  old_node_attr = None,
  old_edge_attr = None,
  old_body = None,
  old_strict = False,
**  kwargs 
)
Create a digraph representation of specified tree.

Note
----
For more information please visit
https://graphviz.readthedocs.io/en/stable/api.html#digraph.

Parameters
----------
booster : Booster or LGBMModel
    Booster or LGBMModel instance to be converted.
tree_index : int, optional (default=0)
    The index of a target tree to convert.
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', 'leaf_count'.
precision : int or None, optional (default=None)
    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
-------
graph : graphviz.Digraph
    The digraph representation of specified tree.

◆ plot_importance()

lightgbm.plotting.plot_importance (   booster,
  ax = None,
  height = 0.2,
  xlim = None,
  ylim = None,
  title = 'Feature importance',
  xlabel = 'Feature importance',
  ylabel = 'Features',
  importance_type = 'split',
  max_num_features = None,
  ignore_zero = True,
  figsize = None,
  grid = True,
  precision = None,
**  kwargs 
)
Plot model's feature importances.

Parameters
----------
booster : Booster or LGBMModel
    Booster or LGBMModel instance which feature importance should be plotted.
ax : matplotlib.axes.Axes or None, optional (default=None)
    Target axes instance.
    If None, new figure and axes will be created.
height : float, optional (default=0.2)
    Bar height, passed to ``ax.barh()``.
xlim : tuple of 2 elements or None, optional (default=None)
    Tuple passed to ``ax.xlim()``.
ylim : tuple of 2 elements or None, optional (default=None)
    Tuple passed to ``ax.ylim()``.
title : string or None, optional (default="Feature importance")
    Axes title.
    If None, title is disabled.
xlabel : string or None, optional (default="Feature importance")
    X-axis title label.
    If None, title is disabled.
ylabel : string or None, optional (default="Features")
    Y-axis title label.
    If None, title is disabled.
importance_type : string, optional (default="split")
    How the importance is calculated.
    If "split", result contains numbers of times the feature is used in a model.
    If "gain", result contains total gains of splits which use the feature.
max_num_features : int or None, optional (default=None)
    Max number of top features displayed on plot.
    If None or <1, all features will be displayed.
ignore_zero : bool, optional (default=True)
    Whether to ignore features with zero importance.
figsize : tuple of 2 elements or None, optional (default=None)
    Figure size.
grid : bool, optional (default=True)
    Whether to add a grid for axes.
precision : int or None, optional (default=None)
    Used to restrict the display of floating point values to a certain precision.
**kwargs
    Other parameters passed to ``ax.barh()``.

Returns
-------
ax : matplotlib.axes.Axes
    The plot with model's feature importances.

◆ plot_metric()

lightgbm.plotting.plot_metric (   booster,
  metric = None,
  dataset_names = None,
  ax = None,
  xlim = None,
  ylim = None,
  title = 'Metric during training',
  xlabel = 'Iterations',
  ylabel = 'auto',
  figsize = None,
  grid = True 
)
Plot one metric during training.

Parameters
----------
booster : dict or LGBMModel
    Dictionary returned from ``lightgbm.train()`` or LGBMModel instance.
metric : string or None, optional (default=None)
    The metric name to plot.
    Only one metric supported because different metrics have various scales.
    If None, first metric picked from dictionary (according to hashcode).
dataset_names : list of strings or None, optional (default=None)
    List of the dataset names which are used to calculate metric to plot.
    If None, all datasets are used.
ax : matplotlib.axes.Axes or None, optional (default=None)
    Target axes instance.
    If None, new figure and axes will be created.
xlim : tuple of 2 elements or None, optional (default=None)
    Tuple passed to ``ax.xlim()``.
ylim : tuple of 2 elements or None, optional (default=None)
    Tuple passed to ``ax.ylim()``.
title : string or None, optional (default="Metric during training")
    Axes title.
    If None, title is disabled.
xlabel : string or None, optional (default="Iterations")
    X-axis title label.
    If None, title is disabled.
ylabel : string or None, optional (default="auto")
    Y-axis title label.
    If 'auto', metric name is used.
    If None, title is disabled.
figsize : tuple of 2 elements or None, optional (default=None)
    Figure size.
grid : bool, optional (default=True)
    Whether to add a grid for axes.

Returns
-------
ax : matplotlib.axes.Axes
    The plot with metric's history over the training.

◆ plot_tree()

lightgbm.plotting.plot_tree (   booster,
  ax = None,
  tree_index = 0,
  figsize = None,
  old_graph_attr = None,
  old_node_attr = None,
  old_edge_attr = None,
  show_info = None,
  precision = None,
**  kwargs 
)
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.
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', 'leaf_count'.
precision : int or None, optional (default=None)
    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 : matplotlib.axes.Axes
    The plot with single tree.