gpt4 book ai didi

python - XGBoost 包中的特征分数(/重要性)是如何计算的?

转载 作者:IT老高 更新时间:2023-10-28 20:22:40 24 4
gpt4 key购买 nike

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

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

输出: Graph of feature importance Graph of feature importance

最佳答案

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

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

即这个变量 split 了多少次?

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

[这里.. 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

关于python - XGBoost 包中的特征分数(/重要性)是如何计算的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34218245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com