【问题标题】:How is the feature score(/importance) in the XGBoost package calculated?XGBoost 包中的特征分数(/重要性)是如何计算的?
【发布时间】:2016-03-17 01:17:37
【问题描述】:

xgb.importance 命令返回由 f 分数衡量的特征重要性图。

这个f分数代表什么,它是如何计算的?

输出: Graph of feature importance

【问题讨论】:

  • 这个问题与语言无关,所以我将其标记为rpython,因为它们是 xgboost 的前 2 大语言用户。

标签: python r classification feature-selection xgboost


【解决方案1】:

这是一个指标,它简单地总结了每个特征被分割的次数。类似于 R 版本中的频率度量。https://cran.r-project.org/web/packages/xgboost/xgboost.pdf

这是您可以获得的基本特征重要性指标。

即这个变量分裂了多少次?

此方法的代码显示它只是在所有树中添加给定特征的存在。

[这里..https://github.com/dmlc/xgboost/blob/master/python-package/xgboost/core.py#L953][1]

def get_fscore(self, fmap=''):
    """Get feature importance of each feature.
    Parameters
    ----------
    fmap: str (optional)
       The name of feature map file
    """
    trees = self.get_dump(fmap)  ## dump all the trees to text
    fmap = {}                    
    for tree in trees:              ## loop through the trees
        for line in tree.split('\n'):     # text processing
            arr = line.split('[')
            if len(arr) == 1:             # text processing 
                continue
            fid = arr[1].split(']')[0]    # text processing
            fid = fid.split('<')[0]       # split on the greater/less(find variable name)

            if fid not in fmap:  # if the feature id hasn't been seen yet
                fmap[fid] = 1    # add it
            else:
                fmap[fid] += 1   # else increment it
    return fmap                  # return the fmap, which has the counts of each time a  variable was split on

【讨论】:

  • 您好,谢谢您的回答。我在理解源代码时遇到了麻烦。你能向我解释一下那个函数到底发生了什么吗?
  • 我其实有点理解。我进入核心文件并在使用 xbg.plot_importance 时打印了行变量。然后分割每一行以仅提取特征名称并计算每个分割的次数?
  • @ishido 你明白了.. 添加了一些 cmets.. 没有看到树木的文本转储,很难准确地说出所有刺痛操作都在做什么,但我希望更大的方案很清楚
  • 仅供参考:它现在已被移动,而且功能更多 - github.com/dmlc/xgboost/blob/b4f952b/python-package/xgboost/… - 下次建议使用提交哈希而不是 master...
【解决方案2】:

我发现这个答案正确而彻底。它显示了 feature_importances 的实现。

https://stats.stackexchange.com/questions/162162/relative-variable-importance-for-boosting

【讨论】:

    猜你喜欢
    • 2020-10-26
    • 2019-04-15
    • 2019-12-13
    • 1970-01-01
    • 2022-01-19
    • 2017-10-25
    • 2021-08-22
    • 2019-12-19
    • 1970-01-01
    相关资源
    最近更新 更多