readRDS.lgb.Booster.Rd 1.42 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}
5
\title{readRDS for \code{lgb.Booster} models (DEPRECATED)}
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
19
20
21
Calls \code{readRDS} in what is expected to be a serialized \code{lgb.Booster} object,
             and then restores its handle through \code{lgb.restore_handle}.

             \bold{This function throws a warning and will be removed in future versions.}
Guolin Ke's avatar
Guolin Ke committed
22
23
}
\examples{
24
\donttest{
25
26
27
28
29
30
31
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)
32
33
34
35
36
params <- list(
  objective = "regression"
  , metric = "l2"
  , min_data = 1L
  , learning_rate = 1.0
37
  , num_threads = 2L
38
)
39
valids <- list(test = dtest)
40
41
42
model <- lgb.train(
  params = params
  , data = dtrain
43
  , nrounds = 10L
44
  , valids = valids
45
  , early_stopping_rounds = 5L
46
)
47
48
49
model_file <- tempfile(fileext = ".rds")
saveRDS.lgb.Booster(model, model_file)
new_model <- readRDS.lgb.Booster(model_file)
50
}
Guolin Ke's avatar
Guolin Ke committed
51
}