Skip to content

Commit

Permalink
[R-package] remove readRDS.lgb.Booster() and saveRDS.lgb.Booster() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Dec 22, 2023
1 parent 051eb22 commit 4588d64
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 341 deletions.
2 changes: 0 additions & 2 deletions R-package/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export(lgb.restore_handle)
export(lgb.save)
export(lgb.train)
export(lightgbm)
export(readRDS.lgb.Booster)
export(saveRDS.lgb.Booster)
export(setLGBMthreads)
export(set_field)
export(slice)
Expand Down
50 changes: 0 additions & 50 deletions R-package/R/readRDS.lgb.Booster.R

This file was deleted.

80 changes: 0 additions & 80 deletions R-package/R/saveRDS.lgb.Booster.R

This file was deleted.

53 changes: 0 additions & 53 deletions R-package/man/readRDS.lgb.Booster.Rd

This file was deleted.

75 changes: 0 additions & 75 deletions R-package/man/saveRDS.lgb.Booster.Rd

This file was deleted.

2 changes: 0 additions & 2 deletions R-package/pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ reference:
- '`lgb.save`'
- '`lgb.load`'
- '`lgb.model.dt.tree`'
- '`saveRDS.lgb.Booster`'
- '`readRDS.lgb.Booster`'
- title: Model Interpretation
desc: Analyze your models
contents:
Expand Down
79 changes: 0 additions & 79 deletions R-package/tests/testthat/test_lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -1252,45 +1252,6 @@ test_that("lgb.cv() correctly handles passing through params to the model file",

})

test_that("params (including dataset params) should be stored in .rds file for Booster", {
data(agaricus.train, package = "lightgbm")
dtrain <- lgb.Dataset(
agaricus.train$data
, label = agaricus.train$label
, params = list(
max_bin = 17L
)
)
params <- list(
objective = "binary"
, max_depth = 4L
, bagging_fraction = 0.8
, verbose = .LGB_VERBOSITY
, num_threads = .LGB_MAX_THREADS
)
bst <- Booster$new(
params = params
, train_set = dtrain
)
bst_file <- tempfile(fileext = ".rds")
expect_warning(saveRDS.lgb.Booster(bst, file = bst_file))

expect_warning({
bst_from_file <- readRDS.lgb.Booster(file = bst_file)
})
expect_identical(
bst_from_file$params
, list(
objective = "binary"
, max_depth = 4L
, bagging_fraction = 0.8
, verbose = .LGB_VERBOSITY
, num_threads = .LGB_MAX_THREADS
, max_bin = 17L
)
)
})

test_that("params (including dataset params) should be stored in .rds file for Booster", {
data(agaricus.train, package = "lightgbm")
dtrain <- lgb.Dataset(
Expand Down Expand Up @@ -1350,46 +1311,6 @@ test_that("Handle is automatically restored when calling predict", {
expect_equal(pred_before, pred_after)
})

test_that("boosters with linear models at leaves work with saveRDS.lgb.Booster and readRDS.lgb.Booster", {
X <- matrix(rnorm(100L), ncol = 1L)
labels <- 2L * X + runif(nrow(X), 0L, 0.1)
dtrain <- lgb.Dataset(
data = X
, label = labels
)

params <- list(
objective = "regression"
, verbose = .LGB_VERBOSITY
, metric = "mse"
, seed = 0L
, num_leaves = 2L
, num_threads = .LGB_MAX_THREADS
)

bst <- lgb.train(
data = dtrain
, nrounds = 10L
, params = params
)
expect_true(.is_Booster(bst))

# save predictions, then write the model to a file and destroy it in R
preds <- predict(bst, X)
model_file <- tempfile(fileext = ".rds")
expect_warning(saveRDS.lgb.Booster(bst, file = model_file))
bst$finalize()
expect_null(bst$.__enclos_env__$private$handle)
rm(bst)

# load the booster and make predictions...should be the same
expect_warning({
bst2 <- readRDS.lgb.Booster(file = model_file)
})
preds2 <- predict(bst2, X)
expect_identical(preds, preds2)
})

test_that("boosters with linear models at leaves can be written to RDS and re-loaded successfully", {
X <- matrix(rnorm(100L), ncol = 1L)
labels <- 2L * X + runif(nrow(X), 0L, 0.1)
Expand Down

0 comments on commit 4588d64

Please sign in to comment.