R/lgb.restore_handle.R
lgb.restore_handle.Rd
After a LightGBM model object is de-serialized through functions such as save
or
saveRDS
, its underlying C++ object will be blank and needs to be restored to able to use it. Such
object is restored automatically when calling functions such as predict
, but this function can be
used to forcibly restore it beforehand. Note that the object will be modified in-place.
New in version 4.0.0
lgb.restore_handle(model)
lgb.Booster
(the same `model` object that was passed as input, invisibly).
Be aware that fast single-row prediction configurations are not restored through this
function. If you wish to make fast single-row predictions using a lgb.Booster
loaded this way,
call lgb.configure_fast_predict on the loaded lgb.Booster
object.
# \donttest{
library(lightgbm)
data("agaricus.train")
model <- lightgbm(
agaricus.train$data
, agaricus.train$label
, params = list(objective = "binary")
, nrounds = 5L
, verbose = 0
, num_threads = 2L
)
#> [LightGBM] [Warning] No further splits with positive gain, best gain: -inf
#> [LightGBM] [Warning] No further splits with positive gain, best gain: -inf
#> [LightGBM] [Warning] No further splits with positive gain, best gain: -inf
#> [LightGBM] [Warning] No further splits with positive gain, best gain: -inf
#> [LightGBM] [Warning] No further splits with positive gain, best gain: -inf
fname <- tempfile(fileext="rds")
saveRDS(model, fname)
model_new <- readRDS(fname)
model_new$check_null_handle()
#> [1] TRUE
lgb.restore_handle(model_new)
model_new$check_null_handle()
#> [1] FALSE
# }