lightgbm.plot_importance

lightgbm.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, dpi=None, grid=True, precision=3, **kwargs)[source]

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.
  • dpi (int or None, optional (default=None)) – Resolution of the figure.
  • grid (bool, optional (default=True)) – Whether to add a grid for axes.
  • 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 ax.barh().
Returns:

ax – The plot with model’s feature importances.

Return type:

matplotlib.axes.Axes