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 figu
(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)
| 27 | |
| 28 | |
| 29 | def plot_importance(booster, ax=None, height=0.2, |
| 30 | xlim=None, ylim=None, title='Feature importance', |
| 31 | xlabel='Feature importance', ylabel='Features', |
| 32 | importance_type='split', max_num_features=None, |
| 33 | ignore_zero=True, figsize=None, dpi=None, grid=True, |
| 34 | precision=3, **kwargs): |
| 35 | """Plot model's feature importances. |
| 36 | |
| 37 | Parameters |
| 38 | ---------- |
| 39 | booster : Booster or LGBMModel |
| 40 | Booster or LGBMModel instance which feature importance should be plotted. |
| 41 | ax : matplotlib.axes.Axes or None, optional (default=None) |
| 42 | Target axes instance. |
| 43 | If None, new figure and axes will be created. |
| 44 | height : float, optional (default=0.2) |
| 45 | Bar height, passed to ``ax.barh()``. |
| 46 | xlim : tuple of 2 elements or None, optional (default=None) |
| 47 | Tuple passed to ``ax.xlim()``. |
| 48 | ylim : tuple of 2 elements or None, optional (default=None) |
| 49 | Tuple passed to ``ax.ylim()``. |
| 50 | title : string or None, optional (default="Feature importance") |
| 51 | Axes title. |
| 52 | If None, title is disabled. |
| 53 | xlabel : string or None, optional (default="Feature importance") |
| 54 | X-axis title label. |
| 55 | If None, title is disabled. |
| 56 | ylabel : string or None, optional (default="Features") |
| 57 | Y-axis title label. |
| 58 | If None, title is disabled. |
| 59 | importance_type : string, optional (default="split") |
| 60 | How the importance is calculated. |
| 61 | If "split", result contains numbers of times the feature is used in a model. |
| 62 | If "gain", result contains total gains of splits which use the feature. |
| 63 | max_num_features : int or None, optional (default=None) |
| 64 | Max number of top features displayed on plot. |
| 65 | If None or <1, all features will be displayed. |
| 66 | ignore_zero : bool, optional (default=True) |
| 67 | Whether to ignore features with zero importance. |
| 68 | figsize : tuple of 2 elements or None, optional (default=None) |
| 69 | Figure size. |
| 70 | dpi : int or None, optional (default=None) |
| 71 | Resolution of the figure. |
| 72 | grid : bool, optional (default=True) |
| 73 | Whether to add a grid for axes. |
| 74 | precision : int or None, optional (default=3) |
| 75 | Used to restrict the display of floating point values to a certain precision. |
| 76 | **kwargs |
| 77 | Other parameters passed to ``ax.barh()``. |
| 78 | |
| 79 | Returns |
| 80 | ------- |
| 81 | ax : matplotlib.axes.Axes |
| 82 | The plot with model's feature importances. |
| 83 | """ |
| 84 | if MATPLOTLIB_INSTALLED: |
| 85 | import matplotlib.pyplot as plt |
| 86 | else: |
nothing calls this directly
no test coverage detected