Dump an xgboost model in text format.
xgb.dump(model, fname = NULL, fmap = "", with_stats = FALSE, dump_format = c("text", "json"), ...)
model | the model object. |
---|---|
fname | the name of the text file where to save the model text dump.
If not provided or set to |
fmap | feature map file representing feature types. Detailed description could be found at https://github.com/dmlc/xgboost/wiki/Binary-Classification#dump-model. See demo/ for walkthrough example in R, and https://github.com/dmlc/xgboost/blob/master/demo/data/featmap.txt for example Format. |
with_stats | whether to dump some additional statistics about the splits. When this option is on, the model dump contains two additional values: gain is the approximate loss function gain we get in each split; cover is the sum of second order gradient in each node. |
dump_format | either 'text' or 'json' format could be specified. |
... | currently not used |
If fname is not provided or set to NULL
the function will return the model
as a character
vector. Otherwise it will return TRUE
.
data(agaricus.train, package='xgboost') data(agaricus.test, package='xgboost') train <- agaricus.train test <- agaricus.test bst <- xgboost(data = train$data, label = train$label, max_depth = 2, eta = 1, nthread = 2, nrounds = 2, objective = "binary:logistic")#> [1] train-error:0.046522 #> [2] train-error:0.022263# save the model in file 'xgb.model.dump' dump_path = file.path(tempdir(), 'model.dump') xgb.dump(bst, dump_path, with_stats = TRUE)#> [1] TRUE#> [1] "booster[0]" #> [2] "0:[f28<-9.53674316e-07] yes=1,no=2,missing=1,gain=4000.53101,cover=1628.25" #> [3] "1:[f55<-9.53674316e-07] yes=3,no=4,missing=3,gain=1158.21204,cover=924.5" #> [4] "3:leaf=1.71217716,cover=812" #> [5] "4:leaf=-1.70044053,cover=112.5" #> [6] "2:[f108<-9.53674316e-07] yes=5,no=6,missing=5,gain=198.173828,cover=703.75" #> [7] "5:leaf=-1.94070864,cover=690.5" #> [8] "6:leaf=1.85964918,cover=13.25" #> [9] "booster[1]" #> [10] "0:[f59<-9.53674316e-07] yes=1,no=2,missing=1,gain=832.545044,cover=788.852051" #> [11] "1:[f28<-9.53674316e-07] yes=3,no=4,missing=3,gain=569.725098,cover=768.389709" #> [12] "3:leaf=0.78471756,cover=458.936859" #> [13] "4:leaf=-0.968530357,cover=309.45282" #> [14] "2:leaf=-6.23624468,cover=20.462389"#> [ #> { "nodeid": 0, "depth": 0, "split": 28, "split_condition": -9.53674316e-07, "yes": 1, "no": 2, "missing": 1, "gain": 4000.53101, "cover": 1628.25, "children": [ #> { "nodeid": 1, "depth": 1, "split": 55, "split_condition": -9.53674316e-07, "yes": 3, "no": 4, "missing": 3, "gain": 1158.21204, "cover": 924.5, "children": [ #> { "nodeid": 3, "leaf": 1.71217716, "cover": 812 }, #> { "nodeid": 4, "leaf": -1.70044053, "cover": 112.5 } #> ]}, #> { "nodeid": 2, "depth": 1, "split": 108, "split_condition": -9.53674316e-07, "yes": 5, "no": 6, "missing": 5, "gain": 198.173828, "cover": 703.75, "children": [ #> { "nodeid": 5, "leaf": -1.94070864, "cover": 690.5 }, #> { "nodeid": 6, "leaf": 1.85964918, "cover": 13.25 } #> ]} #> ]}, #> { "nodeid": 0, "depth": 0, "split": 59, "split_condition": -9.53674316e-07, "yes": 1, "no": 2, "missing": 1, "gain": 832.545044, "cover": 788.852051, "children": [ #> { "nodeid": 1, "depth": 1, "split": 28, "split_condition": -9.53674316e-07, "yes": 3, "no": 4, "missing": 3, "gain": 569.725098, "cover": 768.389709, "children": [ #> { "nodeid": 3, "leaf": 0.78471756, "cover": 458.936859 }, #> { "nodeid": 4, "leaf": -0.968530357, "cover": 309.45282 } #> ]}, #> { "nodeid": 2, "leaf": -6.23624468, "cover": 20.462389 } #> ]} #> ]