当前位置:   article > 正文

决策树分析特征重要性可视化无监督特征筛选_weights = dtc.feature_importances_

weights = dtc.feature_importances_

 

  1. from sklearn.tree import DecisionTreeClassifier
  2. dtc = DecisionTreeClassifier() # 初始化
  3. dtc.fit(x_train, y_train) # 训练
  4. # 获取特征权重值
  5. weights = dtc.feature_importances_
  6. print('>>>特征权重值\n', weights)
  7. # 索引降序排列
  8. sort_index = np.argsort(weights)[::-1]
  9. # 对应的特征名
  10. name = [df.iloc[:, 1:].columns[i] for i in sort_index]
  11. print('\n>>>索引降序排列\n', sort_index)
  12. print('\n>>>特征名\n', name)
  13. # 可视化
  14. plt.bar(x=name, height=weights[sort_index], color='r')
  15. _ = plt.xticks(rotation=90)
  16. plt.title('Feature Weights')

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/526675
推荐阅读
  

闽ICP备14008679号