data("ToothGrowth")
x <- ToothGrowth[, c("len", "dose")]
y <- ToothGrowth$supp
model <- xgboost(
x, y,
nthreads = 1L,
nrounds = 3L,
max_depth = 3L
)
# plot the first tree
xgb.plot.tree(model, tree_idx = 1)
# Below is an example of how to save this plot to a file.
if (require("DiagrammeR") && require("htmlwidgets")) {
fname <- file.path(tempdir(), "plot.html'")
gr <- xgb.plot.tree(model, tree_idx = 1)
htmlwidgets::saveWidget(gr, fname)
}
Run the code above in your browser using DataLab