may*_*our 5 python decision-tree multiclass-classification
我构建了一个决策树,它也为我的分类提供了特征重要性。但是我怎么能告诉我的程序给我每个类的特征重要性呢?为了给我整体功能的重要性,我有这个代码:
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()
Run Code Online (Sandbox Code Playgroud)
我有四个类 - 0、1、2、3。有人知道解决方案吗?
| 归档时间: |
|
| 查看次数: |
1330 次 |
| 最近记录: |