# Basic use:
data(agaricus.train, package = "xgboost")
## Keep the number of threads to 1 for examples
nthread <- 1
data.table::setDTthreads(nthread)
bst <- xgb.train(
data = xgb.DMatrix(agaricus.train$data, label = agaricus.train$label, nthread = 1),
nrounds = 2,
params = xgb.params(
max_depth = 2,
nthread = nthread,
objective = "binary:logistic"
)
)
# This bst model already has feature_names stored with it, so those would be used when
# feature_names is not set:
dt <- xgb.model.dt.tree(bst)
# How to match feature names of splits that are following a current 'Yes' branch:
merge(
dt,
dt[, .(ID, Y.Feature = Feature)], by.x = "Yes", by.y = "ID", all.x = TRUE
)[
order(Tree, Node)
]
Run the code above in your browser using DataLab