readRDS.lgb.Booster.Rd 1.22 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/readRDS.lgb.Booster.R
\name{readRDS.lgb.Booster}
\alias{readRDS.lgb.Booster}
Nikita Titov's avatar
Nikita Titov committed
5
\title{readRDS for \code{lgb.Booster} models}
Guolin Ke's avatar
Guolin Ke committed
6
\usage{
7
readRDS.lgb.Booster(file, refhook = NULL)
Guolin Ke's avatar
Guolin Ke committed
8
9
10
11
12
13
14
}
\arguments{
\item{file}{a connection or the name of the file where the R object is saved to or read from.}

\item{refhook}{a hook function for handling reference objects.}
}
\value{
15
\code{lgb.Booster}
Guolin Ke's avatar
Guolin Ke committed
16
17
}
\description{
18
Attempts to load a model stored in a \code{.rds} file, using \code{\link[base]{readRDS}}
Guolin Ke's avatar
Guolin Ke committed
19
20
}
\examples{
21
\donttest{
22
23
24
25
26
27
28
library(lightgbm)
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
data(agaricus.test, package = "lightgbm")
test <- agaricus.test
dtest <- lgb.Dataset.create.valid(dtrain, test$data, label = test$label)
29
30
31
32
33
34
params <- list(
  objective = "regression"
  , metric = "l2"
  , min_data = 1L
  , learning_rate = 1.0
)
35
valids <- list(test = dtest)
36
37
38
model <- lgb.train(
  params = params
  , data = dtrain
39
  , nrounds = 10L
40
  , valids = valids
41
  , early_stopping_rounds = 5L
42
)
43
44
45
model_file <- tempfile(fileext = ".rds")
saveRDS.lgb.Booster(model, model_file)
new_model <- readRDS.lgb.Booster(model_file)
46
}
Guolin Ke's avatar
Guolin Ke committed
47
}