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
5a89a76d
Unverified
Commit
5a89a76d
authored
Dec 23, 2017
by
Guolin Ke
Committed by
GitHub
Dec 23, 2017
Browse files
fix early stopping edge case (#1133)
* fix early stopping edge case * fix message. * fix tests * fix GPU tests.
parent
9ee10754
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
6 deletions
+25
-6
.travis/amd_sdk.sh
.travis/amd_sdk.sh
+2
-2
R-package/R/callback.R
R-package/R/callback.R
+17
-3
python-package/lightgbm/callback.py
python-package/lightgbm/callback.py
+5
-0
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+1
-1
No files found.
.travis/amd_sdk.sh
View file @
5a89a76d
...
...
@@ -12,7 +12,7 @@ POSTID_STRING='name="post_id"'
NONCE2_STRING
=
'name="amd_developer_central_nonce"'
#For newest FORM=`wget -qO - $URL | sed -n '/download-2/,/64-bit/p'`
FORM
=
`
wget
-qO
-
$URL
|
sed
-n
'/download-5/,/64-bit/p'
`
FORM
=
`
wget
--no-check-certificate
-qO
-
$URL
|
sed
-n
'/download-5/,/64-bit/p'
`
# Get nonce from form
NONCE1
=
`
echo
$FORM
|
awk
-F
${
NONCE1_STRING
}
'{print $2}'
`
...
...
@@ -29,7 +29,7 @@ FILE=`echo $FORM | awk -F ${FILE_STRING} '{print $2}'`
FILE
=
`
echo
$FILE
|
awk
-F
'"'
'{print $2}'
`
echo
$FILE
FORM
=
`
wget
-qO
-
$URLDOWN
--post-data
"amd_developer_central_downloads_page_nonce=
${
NONCE1
}
&f=
${
FILE
}
&post_id=
${
POSTID
}
"
`
FORM
=
`
wget
--no-check-certificate
-qO
-
$URLDOWN
--post-data
"amd_developer_central_downloads_page_nonce=
${
NONCE1
}
&f=
${
FILE
}
&post_id=
${
POSTID
}
"
`
NONCE2
=
`
echo
$FORM
|
awk
-F
${
NONCE2_STRING
}
'{print $2}'
`
NONCE2
=
`
echo
$NONCE2
|
awk
-F
'"'
'{print $2}'
`
...
...
R-package/R/callback.R
View file @
5a89a76d
...
...
@@ -356,13 +356,27 @@ cb.early.stop <- function(stopping_rounds, verbose = TRUE) {
# Store best iteration and stop
env
$
best_iter
<-
best_iter
[
i
]
env
$
met_early_stop
<-
TRUE
}
}
if
(
isFALSE
(
env
$
met_early_stop
)
&&
cur_iter
==
env
$
end_iteration
)
{
# Check if model is not null
if
(
!
is.null
(
env
$
model
))
{
env
$
model
$
best_score
<-
best_score
[
i
]
env
$
model
$
best_iter
<-
best_iter
[
i
]
}
# Print message if verbose
if
(
isTRUE
(
verbose
))
{
cat
(
"Did not meet early stopping, best iteration is:"
,
"\n"
)
cat
(
best_msg
[[
i
]],
"\n"
)
}
# Store best iteration and stop
env
$
best_iter
<-
best_iter
[
i
]
env
$
met_early_stop
<-
TRUE
}
}
}
# Set attributes
...
...
python-package/lightgbm/callback.py
View file @
5a89a76d
...
...
@@ -206,5 +206,10 @@ def early_stopping(stopping_rounds, verbose=True):
print
(
'Early stopping, best iteration is:
\n
[%d]
\t
%s'
%
(
best_iter
[
i
]
+
1
,
'
\t
'
.
join
([
_format_eval_result
(
x
)
for
x
in
best_score_list
[
i
]])))
raise
EarlyStopException
(
best_iter
[
i
],
best_score_list
[
i
])
if
env
.
iteration
==
env
.
end_iteration
-
1
:
if
verbose
:
print
(
'Did not meet early stopping. Best iteration is:
\n
[%d]
\t
%s'
%
(
best_iter
[
i
]
+
1
,
'
\t
'
.
join
([
_format_eval_result
(
x
)
for
x
in
best_score_list
[
i
]])))
raise
EarlyStopException
(
best_iter
[
i
],
best_score_list
[
i
])
callback
.
order
=
30
return
callback
tests/python_package_test/test_engine.py
View file @
5a89a76d
...
...
@@ -344,7 +344,7 @@ class TestEngine(unittest.TestCase):
valid_names
=
valid_set_name
,
verbose_eval
=
False
,
early_stopping_rounds
=
5
)
self
.
assertEqual
(
gbm
.
best_iteration
,
0
)
self
.
assertEqual
(
gbm
.
best_iteration
,
1
0
)
self
.
assertIn
(
valid_set_name
,
gbm
.
best_score
)
self
.
assertIn
(
'binary_logloss'
,
gbm
.
best_score
[
valid_set_name
])
# early stopping occurs
...
...
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