Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-package] added tests on LGBM_BoosterRollbackOneIter_R #3006

Merged
merged 1 commit into from
Apr 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions R-package/tests/testthat/test_lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,35 @@ test_that("Creating a Booster from a Dataset with an existing predictor should w
expect_identical(bst_from_ds$eval_train(), list())
expect_equal(bst_from_ds$current_iter(), nrounds)
})

test_that("Booster$rollback_one_iter() should work as expected", {
set.seed(708L)
data(agaricus.train, package = "lightgbm")
data(agaricus.test, package = "lightgbm")
train <- agaricus.train
test <- agaricus.test
nrounds <- 5L
bst <- lightgbm(
data = as.matrix(train$data)
, label = train$label
, num_leaves = 4L
, learning_rate = 1.0
, nrounds = nrounds
, objective = "binary"
)
expect_equal(bst$current_iter(), nrounds)
expect_true(lgb.is.Booster(bst))
logloss <- bst$eval_train()[[1L]][["value"]]
expect_equal(logloss, 0.01904786)

x <- bst$rollback_one_iter()

# rollback_one_iter() should return a booster and modify the original
# booster in place
expect_true(lgb.is.Booster(x))
expect_equal(bst$current_iter(), nrounds - 1L)

# score should now come from the model as of 4 iterations
logloss <- bst$eval_train()[[1L]][["value"]]
expect_equal(logloss, 0.027915146)
})