<tfoot id='I46pP'></tfoot>

    <small id='I46pP'></small><noframes id='I46pP'>

    <legend id='I46pP'><style id='I46pP'><dir id='I46pP'><q id='I46pP'></q></dir></style></legend>
        <i id='I46pP'><tr id='I46pP'><dt id='I46pP'><q id='I46pP'><span id='I46pP'><b id='I46pP'><form id='I46pP'><ins id='I46pP'></ins><ul id='I46pP'></ul><sub id='I46pP'></sub></form><legend id='I46pP'></legend><bdo id='I46pP'><pre id='I46pP'><center id='I46pP'></center></pre></bdo></b><th id='I46pP'></th></span></q></dt></tr></i><div id='I46pP'><tfoot id='I46pP'></tfoot><dl id='I46pP'><fieldset id='I46pP'></fieldset></dl></div>

          <bdo id='I46pP'></bdo><ul id='I46pP'></ul>
      1. 使用要素名称绘制要素重要性

        Plot Feature Importance with feature names(使用要素名称绘制要素重要性)
        <tfoot id='E8rYw'></tfoot>

            <bdo id='E8rYw'></bdo><ul id='E8rYw'></ul>
              <tbody id='E8rYw'></tbody>
            <i id='E8rYw'><tr id='E8rYw'><dt id='E8rYw'><q id='E8rYw'><span id='E8rYw'><b id='E8rYw'><form id='E8rYw'><ins id='E8rYw'></ins><ul id='E8rYw'></ul><sub id='E8rYw'></sub></form><legend id='E8rYw'></legend><bdo id='E8rYw'><pre id='E8rYw'><center id='E8rYw'></center></pre></bdo></b><th id='E8rYw'></th></span></q></dt></tr></i><div id='E8rYw'><tfoot id='E8rYw'></tfoot><dl id='E8rYw'><fieldset id='E8rYw'></fieldset></dl></div>

              <legend id='E8rYw'><style id='E8rYw'><dir id='E8rYw'><q id='E8rYw'></q></dir></style></legend>
              • <small id='E8rYw'></small><noframes id='E8rYw'>

                  本文介绍了使用要素名称绘制要素重要性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在R中有预先构建的函数来绘制随机森林模型的特征重要性。但在蟒蛇中,似乎缺少这种方法。我在matplotlib中搜索方法。

                  model.feature_importances提供以下信息:

                  array([  2.32421835e-03,   7.21472336e-04,   2.70491223e-03,
                           3.34521084e-03,   4.19443238e-03,   1.50108737e-03,
                           3.29160540e-03,   4.82320256e-01,   3.14117333e-03])
                  

                  然后使用以下绘图函数:

                  >> pyplot.bar(range(len(model.feature_importances_)), model.feature_importances_)
                  >> pyplot.show()
                  

                  我得到的是条形图,但我希望得到带有标签的条形图,同时以排序的方式水平显示重要性。我也在探索seaborn,但找不到方法。

                  推荐答案

                  不能完全确定您要查找的内容。从here派生了一个示例。如评论中所述:如果要自定义要素标签,可以将indices更改为plt.yticks(range(X.shape[1]), indices)行的标签列表。

                  import numpy as np
                  import matplotlib.pyplot as plt
                  
                  from sklearn.datasets import make_classification
                  from sklearn.ensemble import ExtraTreesClassifier
                  
                  # Build a classification task using 3 informative features
                  X, y = make_classification(n_samples=1000,
                                             n_features=10,
                                             n_informative=3,
                                             n_redundant=0,
                                             n_repeated=0,
                                             n_classes=2,
                                             random_state=0,
                                             shuffle=False)
                  
                  # Build a forest and compute the feature importances
                  forest = ExtraTreesClassifier(n_estimators=250,
                                                random_state=0)
                  
                  forest.fit(X, y)
                  importances = forest.feature_importances_
                  std = np.std([tree.feature_importances_ for tree in forest.estimators_],
                               axis=0)
                  indices = np.argsort(importances)
                  
                  # Plot the feature importances of the forest
                  plt.figure()
                  plt.title("Feature importances")
                  plt.barh(range(X.shape[1]), importances[indices],
                         color="r", xerr=std[indices], align="center")
                  # If you want to define your own labels,
                  # change indices to a list of labels on the following line.
                  plt.yticks(range(X.shape[1]), indices)
                  plt.ylim([-1, X.shape[1]])
                  plt.show()
                  

                  这篇关于使用要素名称绘制要素重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                    <tbody id='dPUrH'></tbody>

                  1. <tfoot id='dPUrH'></tfoot>
                      <bdo id='dPUrH'></bdo><ul id='dPUrH'></ul>
                      <i id='dPUrH'><tr id='dPUrH'><dt id='dPUrH'><q id='dPUrH'><span id='dPUrH'><b id='dPUrH'><form id='dPUrH'><ins id='dPUrH'></ins><ul id='dPUrH'></ul><sub id='dPUrH'></sub></form><legend id='dPUrH'></legend><bdo id='dPUrH'><pre id='dPUrH'><center id='dPUrH'></center></pre></bdo></b><th id='dPUrH'></th></span></q></dt></tr></i><div id='dPUrH'><tfoot id='dPUrH'></tfoot><dl id='dPUrH'><fieldset id='dPUrH'></fieldset></dl></div>

                        • <small id='dPUrH'></small><noframes id='dPUrH'>

                          1. <legend id='dPUrH'><style id='dPUrH'><dir id='dPUrH'><q id='dPUrH'></q></dir></style></legend>