简体   繁体   English

XGBoost 功能重要性显示重量而不是增益?

[英]XGBoost Feature Importance Showing Weight Instead of Gain?

I'm doing an XGBoost for a linear regression problem and the model works fine but is not printing out the feature importance (gain).我正在为线性回归问题做 XGBoost,model 工作正常,但没有打印出特征重要性(增益)。

The results look like this:结果如下所示:

在此处输入图像描述

But was expecting something like this:但期待这样的事情: 在此处输入图像描述

Does anyone know why this is happening and how to fix it?有谁知道为什么会发生这种情况以及如何解决?

The gain, cover, and frequency metrics are only for the gbtree booster.增益、覆盖和频率指标仅适用于gbtree助推器。 The gblinear booster only gives weight. gblinear助推器只赋予权重。 Perhaps you would prefer to fit the gbtree booster?也许您更愿意安装 gbtree 助推器? That's the default option, and I think, what is most often used.这是默认选项,我认为这是最常用的选项。

library(xgboost)

m1 <- xgboost(
  data  = as.matrix(mtcars[, -1]),
  label = mtcars[, 1],
  nrounds = 50,
  verbose = 0
)

xgb.importance(model = m1)
#>     Feature         Gain       Cover   Frequency
#>  1:     cyl 4.387140e-01 0.020018810 0.039711191
#>  2:      wt 3.033430e-01 0.112723364 0.133574007
#>  3:    disp 1.870484e-01 0.391643155 0.332129964
#>  4:      hp 4.358684e-02 0.112051592 0.126353791
#>  5:    qsec 1.397432e-02 0.192798603 0.211191336
#>  6:    drat 1.082512e-02 0.090420529 0.106498195
#>  7:    carb 2.487836e-03 0.035469569 0.019855596
#>  8:    gear 1.177536e-05 0.015047696 0.009025271
#>  9:      vs 7.260741e-06 0.025392987 0.016245487
#> 10:      am 1.413125e-06 0.004433696 0.005415162

m2 <- xgboost(
  data  = as.matrix(mtcars[, -1]),
  label = mtcars[, 1],
  nrounds = 50,
  verbose = 0,
  booster = "gblinear"
)

xgb.importance(model = m2)
#>     Feature       Weight
#>  1:      am  3.411794186
#>  2:      vs  1.866894841
#>  3:    gear  1.492013931
#>  4:    carb -1.169109583
#>  5:    drat  0.893951356
#>  6:      wt -0.591026664
#>  7:     cyl  0.216187149
#>  8:    qsec  0.150260374
#>  9:      hp -0.014555559
#> 10:    disp -0.004487043

Created on 2022-08-17 by the reprex package (v2.0.1)代表 package (v2.0.1) 于 2022 年 8 月 17 日创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM