admin管理员组文章数量:1650774
在用sklearn的时候经常用到feature_importances_ 来做特征筛选,那这个属性到底是啥呢。
分析gbdt的源码发现来源于每个base_estimator的决策树的
feature_importances_
由此发现计算逻辑来源于cython文件,这个文件可以在其github上查看源代码
而在DecisionTreeRegressor和DecisionTreeClassifier的对feature_importances_定义中
到此决策树的feature_importances_就很清楚了:impurity就是gini值,weighted_n_node_samples 就是各个节点的加权样本数,最后除以根节点nodes[0].weighted_n_node_samples的总样本数。最后还要归一化处理
下面以一个简单的例子来验证下:
上面是决策树跑出来的结果,来看petal width (cm)就是根节点,
f
e
a
t
u
r
e
i
m
p
o
r
t
a
n
c
e
=
(
112
∗
0.6647
−
75
∗
0.4956
−
37
∗
0
)
/
112
=
0.332825
feature_importance=(112*0.6647-75*0.4956-37*0)/112=0.332825
featureimportance=(112∗0.6647−75∗0.4956−37∗0)/112=0.332825,
petal length (cm)的
f
e
a
t
u
r
e
i
m
p
o
r
t
a
n
c
e
=
(
75
∗
0.4956
−
39
∗
0.05
−
36
∗
0.1528
)
/
112
=
0.26535
feature_importance=(75*0.4956-39*0.05-36*0.1528)/112=0.26535
featureimportance=(75∗0.4956−39∗0.05−36∗0.1528)/112=0.26535
归一化:
0.332825
/
(
0.332825
+
0.26535
)
=
0.5564007189
0.332825 / (0.332825+0.26535)=0.5564007189
0.332825/(0.332825+0.26535)=0.5564007189
0.26535
/
(
0.332825
+
0.26535
)
=
0.4435992811
0.26535/ (0.332825+0.26535)=0.4435992811
0.26535/(0.332825+0.26535)=0.4435992811
忽略图上gini计算的小数位数,计算结果相同。
版权声明:本文标题:feature_importances_ - 从决策树到gbdt 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729533433a1205105.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论