[R-package] only warn about early stopping and DART boosting being incompatible if early stopping was requested (#6619)

This commit is contained in:
Serkan Korkmaz 2024-08-21 22:34:15 +02:00 коммит произвёл GitHub
Родитель d67ecf9425
Коммит 5fa615bc48
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 64 добавлений и 5 удалений

Просмотреть файл

@ -295,7 +295,9 @@ lgb.cv <- function(params = list()
# Cannot use early stopping with 'dart' boosting # Cannot use early stopping with 'dart' boosting
if (using_dart) { if (using_dart) {
warning("Early stopping is not available in 'dart' mode.") if (using_early_stopping) {
warning("Early stopping is not available in 'dart' mode.")
}
using_early_stopping <- FALSE using_early_stopping <- FALSE
# Remove the cb_early_stop() function if it was passed in to callbacks # Remove the cb_early_stop() function if it was passed in to callbacks

Просмотреть файл

@ -258,7 +258,9 @@ lgb.train <- function(params = list(),
# Cannot use early stopping with 'dart' boosting # Cannot use early stopping with 'dart' boosting
if (using_dart) { if (using_dart) {
warning("Early stopping is not available in 'dart' mode.") if (using_early_stopping) {
warning("Early stopping is not available in 'dart' mode.")
}
using_early_stopping <- FALSE using_early_stopping <- FALSE
# Remove the cb_early_stop() function if it was passed in to callbacks # Remove the cb_early_stop() function if it was passed in to callbacks

Просмотреть файл

@ -91,7 +91,7 @@ test_that(".PARAMETER_ALIASES() uses the internal session cache", {
expect_false(exists(cache_key, where = .lgb_session_cache_env)) expect_false(exists(cache_key, where = .lgb_session_cache_env))
}) })
test_that("training should warn if you use 'dart' boosting, specified with 'boosting' or aliases", { test_that("training should warn if you use 'dart' boosting with early stopping", {
for (boosting_param in .PARAMETER_ALIASES()[["boosting"]]) { for (boosting_param in .PARAMETER_ALIASES()[["boosting"]]) {
params <- list( params <- list(
num_leaves = 5L num_leaves = 5L
@ -101,14 +101,69 @@ test_that("training should warn if you use 'dart' boosting, specified with 'boos
, num_threads = .LGB_MAX_THREADS , num_threads = .LGB_MAX_THREADS
) )
params[[boosting_param]] <- "dart" params[[boosting_param]] <- "dart"
# warning: early stopping requested
expect_warning({ expect_warning({
result <- lightgbm( result <- lightgbm(
data = train$data data = train$data
, label = train$label , label = train$label
, params = params , params = params
, nrounds = 5L , nrounds = 2L
, verbose = -1L , verbose = .LGB_VERBOSITY
, early_stopping_rounds = 1L
) )
}, regexp = "Early stopping is not available in 'dart' mode") }, regexp = "Early stopping is not available in 'dart' mode")
# no warning: early stopping not requested
expect_silent({
result <- lightgbm(
data = train$data
, label = train$label
, params = params
, nrounds = 2L
, verbose = .LGB_VERBOSITY
, early_stopping_rounds = NULL
)
})
}
})
test_that("lgb.cv() should warn if you use 'dart' boosting with early stopping", {
for (boosting_param in .PARAMETER_ALIASES()[["boosting"]]) {
params <- list(
num_leaves = 5L
, objective = "binary"
, metric = "binary_error"
, num_threads = .LGB_MAX_THREADS
)
params[[boosting_param]] <- "dart"
# warning: early stopping requested
expect_warning({
result <- lgb.cv(
data = lgb.Dataset(
data = train$data
, label = train$label
)
, params = params
, nrounds = 2L
, verbose = .LGB_VERBOSITY
, early_stopping_rounds = 1L
)
}, regexp = "Early stopping is not available in 'dart' mode")
# no warning: early stopping not requested
expect_silent({
result <- lgb.cv(
data = lgb.Dataset(
data = train$data
, label = train$label
)
, params = params
, nrounds = 2L
, verbose = .LGB_VERBOSITY
, early_stopping_rounds = NULL
)
})
} }
}) })