data(agaricus.train, package = "xgboost")
## Keep the number of threads to 2 for examples
nthread <- 2
data.table::setDTthreads(nthread)
model <- xgboost(
agaricus.train$data, factor(agaricus.train$label),
nrounds = 30,
verbosity = 0L,
nthreads = nthread,
max_depth = 15,
learning_rate = 1,
min_child_weight = 50
)
p <- xgb.plot.multi.trees(model, features_keep = 3)
print(p)
# Below is an example of how to save this plot to a file.
if (require("DiagrammeR") && require("DiagrammeRsvg") && require("rsvg")) {
fname <- file.path(tempdir(), "tree.pdf")
gr <- xgb.plot.multi.trees(model, features_keep = 3, render = FALSE)
export_graph(gr, fname, width = 1500, height = 600)
}
Run the code above in your browser using DataLab