Variable Importance in XGBoost Models: A Guide for R Users
You can use the 'xgb.importance' function in the 'xgboost' package of R to check the variable importance in an XGBoost model.
Here's an example code:
library(xgboost)
# load data
data(agaricus.train, package='xgboost')
train <- agaricus.train$data
labels <- agaricus.train$label
# fit xgboost model
xgb_model <- xgboost(data = train, label = labels, max_depth = 2,
eta = 1, nthread = 2, nround = 2, objective = "binary:logistic")
# check variable importance
importance_matrix <- xgb.importance(model = xgb_model)
print(importance_matrix)
In this example, we first load the 'agaricus' dataset from the 'xgboost' package and split it into the input data and labels. Then, we fit an XGBoost model with some hyperparameters. Finally, we use the 'xgb.importance' function to obtain the variable importance matrix of the model and print it. The importance matrix contains the feature names and their corresponding scores, where the higher score indicates more important features.
原文地址: https://www.cveoy.top/t/topic/nyIV 著作权归作者所有。请勿转载和采集!