Extract the individual-algorithm extrinsic importance from an xgboost object, along with the importance rank.

extract_importance_xgboost(fit = NULL, feature_names = "", coef = 0)

Arguments

fit

the xgboost object.

feature_names

the feature names

coef

the Super Learner coefficient associated with the learner.

Value

a tibble, with columns algorithm (the fitted algorithm), feature (the feature), importance (the algorithm-specific extrinsic importance of the feature), rank (the feature importance rank, with 1 indicating the most important feature), and weight

(the algorithm's weight in the Super Learner)

Examples

data("biomarkers")
# subset to complete cases for illustration
cc <- complete.cases(biomarkers)
dat_cc <- biomarkers[cc, ]
# use only the mucinous outcome, not the high-malignancy outcome
y <- dat_cc$mucinous
x <- as.matrix(dat_cc[, !(names(dat_cc) %in% c("mucinous", "high_malignancy"))])
feature_nms <- names(x)
set.seed(20231129)
xgbmat <- xgboost::xgb.DMatrix(data = x, label = y)
# get the fit, using a small number of rounds for illustration only
fit <- xgboost::xgb.train(
  data = xgbmat, nrounds = 10,
  params = list("objective" = "binary:logistic",
                "nthread" = 1, "max_depth" = 1)
)
# extract importance
importance <- extract_importance_xgboost(fit = fit, feature_names = feature_nms)
importance
#> # A tibble: 5 × 5
#>   algorithm feature               importance  rank weight
#>   <chr>     <chr>                      <dbl> <int>  <dbl>
#> 1 xgboost   lab6_ab_score             0.279      1      0
#> 2 xgboost   lab3_muc3ac_score         0.267      2      0
#> 3 xgboost   lab1_telomerase_score     0.204      3      0
#> 4 xgboost   lab1_actb                 0.184      4      0
#> 5 xgboost   institution               0.0656     5      0