I built a decision tree and it also gives me the feature importance for my classification. But how can I tell my program to give me the feature importance for each of my classes? To give me the overall feature importance I have this code:
importances = tree.feature_importances_
#std = np.std([tree.feature_importances_ for tree in forest.estimators_],
# axis=0)
indices = np.argsort(importances)[::-1]
# Print the feature ranking
print("Feature ranking:")
for f in range(X.shape[1]):
print("%d. feature %d (%f)" % (f + 1, indices[f], importances[indices[f]]))
# Plot the feature importances of the forest
plt.figure()
plt.title("Feature importances")
plt.bar(range(X.shape[1]), importances[indices],
color="r", yerr=std[indices], align="center")
plt.xticks(range(X.shape[1]), [feature_cols[i] for i in indices])
plt.xlim([-1, X.shape[1]])
plt.show()
I have four classes - 0, 1, 2, 3. Does someone know a solution?