Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
66600b29
Unverified
Commit
66600b29
authored
Aug 01, 2020
by
James Lamb
Committed by
GitHub
Aug 01, 2020
Browse files
[R-package] fix early_stopping_round <= 0 (#3259)
* [R-package] fix early_stopping_round <= 0 * linting
parent
fecac8e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
2 deletions
+70
-2
R-package/R/lgb.cv.R
R-package/R/lgb.cv.R
+1
-1
R-package/R/lgb.train.R
R-package/R/lgb.train.R
+1
-1
R-package/tests/testthat/test_basic.R
R-package/tests/testthat/test_basic.R
+68
-0
No files found.
R-package/R/lgb.cv.R
View file @
66600b29
...
@@ -232,7 +232,7 @@ lgb.cv <- function(params = list()
...
@@ -232,7 +232,7 @@ lgb.cv <- function(params = list()
}
}
# Did user pass parameters that indicate they want to use early stopping?
# Did user pass parameters that indicate they want to use early stopping?
using_early_stopping_via_args
<-
!
is.null
(
early_stopping_rounds
)
using_early_stopping_via_args
<-
!
is.null
(
early_stopping_rounds
)
&&
early_stopping_rounds
>
0L
boosting_param_names
<-
.PARAMETER_ALIASES
()[[
"boosting"
]]
boosting_param_names
<-
.PARAMETER_ALIASES
()[[
"boosting"
]]
using_dart
<-
any
(
using_dart
<-
any
(
...
...
R-package/R/lgb.train.R
View file @
66600b29
...
@@ -201,7 +201,7 @@ lgb.train <- function(params = list(),
...
@@ -201,7 +201,7 @@ lgb.train <- function(params = list(),
}
}
# Did user pass parameters that indicate they want to use early stopping?
# Did user pass parameters that indicate they want to use early stopping?
using_early_stopping_via_args
<-
!
is.null
(
early_stopping_rounds
)
using_early_stopping_via_args
<-
!
is.null
(
early_stopping_rounds
)
&&
early_stopping_rounds
>
0L
boosting_param_names
<-
.PARAMETER_ALIASES
()[[
"boosting"
]]
boosting_param_names
<-
.PARAMETER_ALIASES
()[[
"boosting"
]]
using_dart
<-
any
(
using_dart
<-
any
(
...
...
R-package/tests/testthat/test_basic.R
View file @
66600b29
...
@@ -545,6 +545,74 @@ test_that("lgb.train() works with early stopping for classification", {
...
@@ -545,6 +545,74 @@ test_that("lgb.train() works with early stopping for classification", {
})
})
test_that
(
"lgb.train() treats early_stopping_rounds<=0 as disabling early stopping"
,
{
set.seed
(
708L
)
trainDF
<-
data.frame
(
"feat1"
=
rep
(
c
(
5.0
,
10.0
),
500L
)
,
"target"
=
rep
(
c
(
0L
,
1L
),
500L
)
)
validDF
<-
data.frame
(
"feat1"
=
rep
(
c
(
5.0
,
10.0
),
50L
)
,
"target"
=
rep
(
c
(
0L
,
1L
),
50L
)
)
dtrain
<-
lgb.Dataset
(
data
=
as.matrix
(
trainDF
[[
"feat1"
]],
drop
=
FALSE
)
,
label
=
trainDF
[[
"target"
]]
)
dvalid
<-
lgb.Dataset
(
data
=
as.matrix
(
validDF
[[
"feat1"
]],
drop
=
FALSE
)
,
label
=
validDF
[[
"target"
]]
)
nrounds
<-
5L
for
(
value
in
c
(
-5L
,
0L
))
{
#----------------------------#
# passed as keyword argument #
#----------------------------#
bst
<-
lgb.train
(
params
=
list
(
objective
=
"binary"
,
metric
=
"binary_error"
)
,
data
=
dtrain
,
nrounds
=
nrounds
,
valids
=
list
(
"valid1"
=
dvalid
)
,
early_stopping_rounds
=
value
)
# a perfect model should be trivial to obtain, but all 10 rounds
# should happen
expect_equal
(
bst
$
best_score
,
0.0
)
expect_equal
(
bst
$
best_iter
,
1L
)
expect_equal
(
length
(
bst
$
record_evals
[[
"valid1"
]][[
"binary_error"
]][[
"eval"
]]),
nrounds
)
#---------------------------#
# passed as parameter alias #
#---------------------------#
bst
<-
lgb.train
(
params
=
list
(
objective
=
"binary"
,
metric
=
"binary_error"
,
n_iter_no_change
=
value
)
,
data
=
dtrain
,
nrounds
=
nrounds
,
valids
=
list
(
"valid1"
=
dvalid
)
)
# a perfect model should be trivial to obtain, but all 10 rounds
# should happen
expect_equal
(
bst
$
best_score
,
0.0
)
expect_equal
(
bst
$
best_iter
,
1L
)
expect_equal
(
length
(
bst
$
record_evals
[[
"valid1"
]][[
"binary_error"
]][[
"eval"
]]),
nrounds
)
}
})
test_that
(
"lgb.train() works with early stopping for classification with a metric that should be maximized"
,
{
test_that
(
"lgb.train() works with early stopping for classification with a metric that should be maximized"
,
{
set.seed
(
708L
)
set.seed
(
708L
)
dtrain
<-
lgb.Dataset
(
dtrain
<-
lgb.Dataset
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment