Debian Codegraph @

man/xgb.dump.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/xgb.dump.R
3 \name{xgb.dump}
4 \alias{xgb.dump}
5 \title{Dump an XGBoost model in text format.}
6 \usage{
7 xgb.dump(
8 model,
9 fname = NULL,
10 fmap = "",
11 with_stats = FALSE,
12 dump_format = c("text", "json", "dot"),
13 ...
14 )
15 }
16 \arguments{
17 \item{model}{The model object.}
18
19 \item{fname}{The name of the text file where to save the model text dump.
20 If not provided or set to \code{NULL}, the model is returned as a character vector.}
21
22 \item{fmap}{Feature map file representing feature types. See demo/ for a walkthrough
23 example in R, and \url{https://github.com/dmlc/xgboost/blob/master/demo/data/featmap.txt}
24 to see an example of the value.}
25
26 \item{with_stats}{Whether to dump some additional statistics about the splits.
27 When this option is on, the model dump contains two additional values:
28 gain is the approximate loss function gain we get in each split;
29 cover is the sum of second order gradient in each node.}
30
31 \item{dump_format}{Either 'text', 'json', or 'dot' (graphviz) format could be specified.
32
33 Format 'dot' for a single tree can be passed directly to packages that consume this format
34 for graph visualization, such as function \code{DiagrammeR::grViz()}}
35
36 \item{...}{Not used.
37
38 Some arguments that were part of this function in previous XGBoost versions are currently
39 deprecated or have been renamed. If a deprecated or renamed argument is passed, will throw
40 a warning (by default) and use its current equivalent instead. This warning will become an
41 error if using the \link[=xgboost-options]{'strict mode' option}.
42
43 If some additional argument is passed that is neither a current function argument nor
44 a deprecated or renamed argument, a warning or error will be thrown depending on the
45 'strict mode' option.
46
47 \bold{Important:} \code{...} will be removed in a future version, and all the current
48 deprecation warnings will become errors. Please use only arguments that form part of
49 the function signature.}
50 }
51 \value{
52 If fname is not provided or set to \code{NULL} the function will return the model
53 as a character vector. Otherwise it will return \code{TRUE}.
54 }
55 \description{
56 Dump an XGBoost model in text format.
57 }
58 \examples{
59 \dontshow{RhpcBLASctl::omp_set_num_threads(1)}
60 data(agaricus.train, package = "xgboost")
61 data(agaricus.test, package = "xgboost")
62
63 train <- agaricus.train
64 test <- agaricus.test
65
66 bst <- xgb.train(
67 data = xgb.DMatrix(train$data, label = train$label, nthread = 1),
68 nrounds = 2,
69 params = xgb.params(
70 max_depth = 2,
71 nthread = 2,
72 objective = "binary:logistic"
73 )
74 )
75
76 # save the model in file 'xgb.model.dump'
77 dump_path = file.path(tempdir(), 'model.dump')
78 xgb.dump(bst, dump_path, with_stats = TRUE)
79
80 # print the model without saving it to a file
81 print(xgb.dump(bst, with_stats = TRUE))
82
83 # print in JSON format:
84 cat(xgb.dump(bst, with_stats = TRUE, dump_format = "json"))
85
86 # plot first tree leveraging the 'dot' format
87 if (requireNamespace('DiagrammeR', quietly = TRUE)) {
88 DiagrammeR::grViz(xgb.dump(bst, dump_format = "dot")[[1L]])
89 }
90 }