Skip to content

Commit

Permalink
[R-package] fix warnings in tests (microsoft#3069)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb authored and odimka committed May 17, 2020
1 parent 4f1c07f commit b0502ab
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions R-package/tests/testthat/test_basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test_that("train and predict binary classification", {


test_that("train and predict softmax", {
set.seed(708L)
lb <- as.numeric(iris$Species) - 1L

bst <- lightgbm(
Expand All @@ -42,15 +43,15 @@ test_that("train and predict softmax", {
, learning_rate = 0.1
, nrounds = 20L
, min_data = 20L
, min_hess = 20.0
, min_hessian = 20.0
, objective = "multiclass"
, metric = "multi_error"
, num_class = 3L
)

expect_false(is.null(bst$record_evals))
record_results <- lgb.get.eval.result(bst, "train", "multi_error")
expect_lt(min(record_results), 0.03)
expect_lt(min(record_results), 0.05)

pred <- predict(bst, as.matrix(iris[, -5L]))
expect_equal(length(pred), nrow(iris) * 3L)
Expand Down Expand Up @@ -125,11 +126,11 @@ test_that("lightgbm() performs evaluation on validation sets if they are provide
set.seed(708L)
dvalid1 <- lgb.Dataset(
data = train$data
, labels = train$label
, label = train$label
)
dvalid2 <- lgb.Dataset(
data = train$data
, labels = train$label
, label = train$label
)
nrounds <- 10L
bst <- lightgbm(
Expand All @@ -156,8 +157,8 @@ test_that("lightgbm() performs evaluation on validation sets if they are provide
expect_length(eval_results[["eval"]], nrounds)
}
expect_true(abs(bst$record_evals[["train"]][["binary_error"]][["eval"]][[1L]] - 0.02226317) < TOLERANCE)
expect_true(abs(bst$record_evals[["valid1"]][["binary_error"]][["eval"]][[1L]] - 0.4825733) < TOLERANCE)
expect_true(abs(bst$record_evals[["valid2"]][["binary_error"]][["eval"]][[1L]] - 0.4825733) < TOLERANCE)
expect_true(abs(bst$record_evals[["valid1"]][["binary_error"]][["eval"]][[1L]] - 0.02226317) < TOLERANCE)
expect_true(abs(bst$record_evals[["valid2"]][["binary_error"]][["eval"]][[1L]] - 0.02226317) < TOLERANCE)
})


Expand Down

0 comments on commit b0502ab

Please sign in to comment.