Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

xgb.Booster.complete

Restore missing parts of an incomplete xgb.Booster object.


Description

It attempts to complete an xgb.Booster object by restoring either its missing raw model memory dump (when it has no raw data but its xgb.Booster.handle is valid) or its missing internal handle (when its xgb.Booster.handle is not valid but it has a raw Booster memory dump).

Usage

xgb.Booster.complete(object, saveraw = TRUE)

Arguments

object

object of class xgb.Booster

saveraw

a flag indicating whether to append raw Booster memory dump data when it doesn't already exist.

Details

While this method is primarily for internal use, it might be useful in some practical situations.

E.g., when an xgb.Booster model is saved as an R object and then is loaded as an R object, its handle (pointer) to an internal xgboost model would be invalid. The majority of xgboost methods should still work for such a model object since those methods would be using xgb.Booster.complete internally. However, one might find it to be more efficient to call the xgb.Booster.complete function explicitly once after loading a model as an R-object. That would prevent further repeated implicit reconstruction of an internal booster model.

Value

An object of xgb.Booster class.

Examples

data(agaricus.train, package='xgboost')
bst <- xgboost(data = agaricus.train$data, label = agaricus.train$label, max_depth = 2,
               eta = 1, nthread = 2, nrounds = 2, objective = "binary:logistic")
saveRDS(bst, "xgb.model.rds")

# Warning: The resulting RDS file is only compatible with the current XGBoost version.
# Refer to the section titled "a-compatibility-note-for-saveRDS-save".
bst1 <- readRDS("xgb.model.rds")
if (file.exists("xgb.model.rds")) file.remove("xgb.model.rds")
# the handle is invalid:
print(bst1$handle)

bst1 <- xgb.Booster.complete(bst1)
# now the handle points to a valid internal booster model:
print(bst1$handle)

xgboost

Extreme Gradient Boosting

v1.4.1.1
Apache License (== 2.0) | file LICENSE
Authors
Tianqi Chen [aut], Tong He [aut, cre], Michael Benesty [aut], Vadim Khotilovich [aut], Yuan Tang [aut] (<https://orcid.org/0000-0001-5243-233X>), Hyunsu Cho [aut], Kailong Chen [aut], Rory Mitchell [aut], Ignacio Cano [aut], Tianyi Zhou [aut], Mu Li [aut], Junyuan Xie [aut], Min Lin [aut], Yifeng Geng [aut], Yutian Li [aut], XGBoost contributors [cph] (base XGBoost implementation)
Initial release
2021-04-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.