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

Function graph_importance

python/play/random_forest_on_token_features.py:20–39  ·  view source on GitHub ↗
(forest)

Source from the content-addressed store, hash-verified

18 std[indices[f]])
19
20def graph_importance(forest):
21 importances = forest.feature_importances_
22 std = np.std([tree.feature_importances_ for tree in forest.estimators_], axis=0)
23 indices = np.argsort(importances)[::-1]
24
25 fig, ax = plt.subplots(1,1)
26 plt.title("Feature importances")
27 xlabels = [token_features[int(i)] for i in indices]
28 plt.bar(range(X_training.shape[1]), importances[indices],
29 color="r", yerr=std[indices], align="center")
30 plt.xticks(range(X_training.shape[1]), xlabels, rotation=15)
31 plt.xlim([-1, X_training.shape[1]])
32 plt.ylim([0, 1])
33
34 for tick in ax.xaxis.get_major_ticks():
35 tick.tick1line.set_markersize(0)
36 tick.tick2line.set_markersize(0)
37 tick.label1.set_horizontalalignment('right')
38
39 plt.show()
40
41data = np.loadtxt("samples/stringtemplate4/style.csv", delimiter=",", skiprows=1)
42

Calls 1

showMethod · 0.45

Tested by

no test coverage detected