Skip to content

Commit

Permalink
[R-package] added tests on LGBM_BoosterRollbackOneIter_R
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Apr 20, 2020
1 parent 0d3e204 commit 2d1d28e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions R-package/tests/testthat/test_lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,37 @@ test_that("If a string and a file are both passed to lgb.load() the file is used
pred2 <- predict(bst2, test$data)
expect_identical(pred, pred2)
})

context("lgb.Booster")

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)
})

0 comments on commit 2d1d28e

Please sign in to comment.