MCPcopy Create free account
hub / github.com/antlr/codebuff / graph_importance

Function graph_importance

python/src/groomlib.py:171–191  ·  view source on GitHub ↗
(forest, feature_names)

Source from the content-addressed store, hash-verified

169
170
171def graph_importance(forest, feature_names):
172 importances = forest.feature_importances_
173 std = np.std([tree.feature_importances_ for tree in forest.estimators_], axis=0)
174 indices = np.argsort(importances)[::-1]
175
176 fig, ax = plt.subplots(1,1)
177 plt.title("Feature importances")
178 xlabels = [feature_names[int(i)] for i in indices]
179 dims = len(importances)
180 plt.bar(range(dims), importances[indices],
181 color="r", yerr=std[indices], align="center")
182 plt.xticks(range(dims), xlabels, rotation=15)
183 plt.xlim([-1, dims])
184 plt.ylim([0, 1])
185
186 for tick in ax.xaxis.get_major_ticks():
187 tick.tick1line.set_markersize(0)
188 tick.tick2line.set_markersize(0)
189 tick.label1.set_horizontalalignment('right')
190
191 plt.show()
192
193
194def print_importances(forest, feature_names, n=10):

Callers

nothing calls this directly

Calls 1

showMethod · 0.45

Tested by

no test coverage detected