зеркало из https://github.com/microsoft/LightGBM.git
[R-package] only warn about early stopping and DART boosting being incompatible if early stopping was requested (#6619)
This commit is contained in:
Родитель
d67ecf9425
Коммит
5fa615bc48
|
@ -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
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Загрузка…
Ссылка в новой задаче