从二进制模型文件加载XGBoost模型。
详细信息
输入文件应包含使用R中的xgb.save()或其他XGBoost接口的适当方法以XGBoost模型格式保存的模型。例如,在Python中训练并保存为XGBoost格式的模型,可以从R中加载。
注意:保存为R对象的模型必须使用相应的R方法加载,而不是通过xgb.load()。
示例
DONTSHOW({RhpcBLASctl::omp_set_num_threads(1)})
data(agaricus.train, package = "xgboost")
data(agaricus.test, package = "xgboost")
## Keep the number of threads to 1 for examples
nthread <- 1
data.table::setDTthreads(nthread)
train <- agaricus.train
test <- agaricus.test
bst <- xgb.train(
  data = xgb.DMatrix(train$data, label = train$label, nthread = 1),
  nrounds = 2,
  params = xgb.params(
    max_depth = 2,
    nthread = nthread,
    objective = "binary:logistic"
  )
)
fname <- file.path(tempdir(), "xgb.ubj")
xgb.save(bst, fname)
bst <- xgb.load(fname)