| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/xgb.load.R |
| 3 |
\name{xgb.load} |
| 4 |
\alias{xgb.load} |
| 5 |
\title{Load XGBoost model from binary file} |
| 6 |
\usage{ |
| 7 |
xgb.load(modelfile) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{modelfile}{The name of the binary input file.} |
| 11 |
} |
| 12 |
\value{ |
| 13 |
An object of \code{xgb.Booster} class. |
| 14 |
} |
| 15 |
\description{ |
| 16 |
Load XGBoost model from binary model file. |
| 17 |
} |
| 18 |
\details{ |
| 19 |
The input file is expected to contain a model saved in an XGBoost model format |
| 20 |
using either \code{\link[=xgb.save]{xgb.save()}} in R, or using some |
| 21 |
appropriate methods from other XGBoost interfaces. E.g., a model trained in Python and |
| 22 |
saved from there in XGBoost format, could be loaded from R. |
| 23 |
|
| 24 |
Note: a model saved as an R object has to be loaded using corresponding R-methods, |
| 25 |
not by \code{\link[=xgb.load]{xgb.load()}}. |
| 26 |
} |
| 27 |
\examples{ |
| 28 |
\dontshow{RhpcBLASctl::omp_set_num_threads(1)} |
| 29 |
data(agaricus.train, package = "xgboost") |
| 30 |
data(agaricus.test, package = "xgboost") |
| 31 |
|
| 32 |
## Keep the number of threads to 1 for examples |
| 33 |
nthread <- 1 |
| 34 |
data.table::setDTthreads(nthread) |
| 35 |
|
| 36 |
train <- agaricus.train |
| 37 |
test <- agaricus.test |
| 38 |
|
| 39 |
bst <- xgb.train( |
| 40 |
data = xgb.DMatrix(train$data, label = train$label, nthread = 1), |
| 41 |
nrounds = 2, |
| 42 |
params = xgb.params( |
| 43 |
max_depth = 2, |
| 44 |
nthread = nthread, |
| 45 |
objective = "binary:logistic" |
| 46 |
) |
| 47 |
) |
| 48 |
|
| 49 |
fname <- file.path(tempdir(), "xgb.ubj") |
| 50 |
xgb.save(bst, fname) |
| 51 |
bst <- xgb.load(fname) |
| 52 |
} |
| 53 |
\seealso{ |
| 54 |
\code{\link[=xgb.save]{xgb.save()}} |
| 55 |
} |