Add show_values option to feature importances plot (#2351)
Adding an option to remove the values from the features importances plot in Python.
This commit is contained in:
parent
0664298bb2
commit
2e9d06443e
@ -15,7 +15,7 @@ def plot_importance(booster, ax=None, height=0.2,
|
||||
xlim=None, ylim=None, title='Feature importance',
|
||||
xlabel='F score', ylabel='Features',
|
||||
importance_type='weight', max_num_features=None,
|
||||
grid=True, **kwargs):
|
||||
grid=True, show_values=True, **kwargs):
|
||||
|
||||
"""Plot importance based on fitted trees.
|
||||
|
||||
@ -45,6 +45,8 @@ def plot_importance(booster, ax=None, height=0.2,
|
||||
X axis title label. To disable, pass None.
|
||||
ylabel : str, default "Features"
|
||||
Y axis title label. To disable, pass None.
|
||||
show_values : bool, default True
|
||||
Show values on plot. To disable, pass False.
|
||||
kwargs :
|
||||
Other keywords passed to ax.barh()
|
||||
|
||||
@ -83,6 +85,7 @@ def plot_importance(booster, ax=None, height=0.2,
|
||||
ylocs = np.arange(len(values))
|
||||
ax.barh(ylocs, values, align='center', height=height, **kwargs)
|
||||
|
||||
if show_values is True:
|
||||
for x, y in zip(values, ylocs):
|
||||
ax.text(x + 1, y, x, va='center')
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user