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
d130bb19
Unverified
Commit
d130bb19
authored
Oct 13, 2021
by
Nikita Titov
Committed by
GitHub
Oct 13, 2021
Browse files
fix behavior for default objective and metric (#4660)
parent
5c8a331b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
8 deletions
+26
-8
R-package/tests/testthat/test_lgb.Booster.R
R-package/tests/testthat/test_lgb.Booster.R
+2
-2
src/io/config.cpp
src/io/config.cpp
+3
-6
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+21
-0
No files found.
R-package/tests/testthat/test_lgb.Booster.R
View file @
d130bb19
...
@@ -415,10 +415,10 @@ test_that("Creating a Booster from a Dataset with an existing predictor should w
...
@@ -415,10 +415,10 @@ test_that("Creating a Booster from a Dataset with an existing predictor should w
expect_true
(
lgb.is.Booster
(
bst
))
expect_true
(
lgb.is.Booster
(
bst
))
expect_equal
(
bst
$
current_iter
(),
nrounds
)
expect_equal
(
bst
$
current_iter
(),
nrounds
)
expect_equal
(
bst
$
eval_train
()[[
1L
]][[
"value"
]],
0.1115352
)
expect_equal
(
bst
$
eval_train
()[[
1L
]][[
"value"
]],
0.1115352
)
expect_true
(
lgb.is.Booster
(
bst_from_ds
))
expect_equal
(
bst_from_ds
$
current_iter
(),
nrounds
)
expect_equal
(
bst_from_ds
$
current_iter
(),
nrounds
)
expect_equal
(
bst_from_ds
$
eval_train
()[[
1L
]][[
"value"
]],
5.65704892
)
dumped_model
<-
jsonlite
::
fromJSON
(
bst
$
dump_model
())
dumped_model
<-
jsonlite
::
fromJSON
(
bst
$
dump_model
())
expect_identical
(
bst_from_ds
$
eval_train
(),
list
())
expect_equal
(
bst_from_ds
$
current_iter
(),
nrounds
)
})
})
test_that
(
"Booster$eval() should work on a Dataset stored in a binary file"
,
{
test_that
(
"Booster$eval() should work on a Dataset stored in a binary file"
,
{
...
...
src/io/config.cpp
View file @
d130bb19
...
@@ -85,7 +85,7 @@ void GetObjectiveType(const std::unordered_map<std::string, std::string>& params
...
@@ -85,7 +85,7 @@ void GetObjectiveType(const std::unordered_map<std::string, std::string>& params
}
}
}
}
void
GetMetricType
(
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
std
::
vector
<
std
::
string
>*
metric
)
{
void
GetMetricType
(
const
std
::
unordered_map
<
std
::
string
,
std
::
string
>&
params
,
const
std
::
string
&
objective
,
std
::
vector
<
std
::
string
>*
metric
)
{
std
::
string
value
;
std
::
string
value
;
if
(
Config
::
GetString
(
params
,
"metric"
,
&
value
))
{
if
(
Config
::
GetString
(
params
,
"metric"
,
&
value
))
{
std
::
transform
(
value
.
begin
(),
value
.
end
(),
value
.
begin
(),
Common
::
tolower
);
std
::
transform
(
value
.
begin
(),
value
.
end
(),
value
.
begin
(),
Common
::
tolower
);
...
@@ -93,10 +93,7 @@ void GetMetricType(const std::unordered_map<std::string, std::string>& params, s
...
@@ -93,10 +93,7 @@ void GetMetricType(const std::unordered_map<std::string, std::string>& params, s
}
}
// add names of objective function if not providing metric
// add names of objective function if not providing metric
if
(
metric
->
empty
()
&&
value
.
size
()
==
0
)
{
if
(
metric
->
empty
()
&&
value
.
size
()
==
0
)
{
if
(
Config
::
GetString
(
params
,
"objective"
,
&
value
))
{
ParseMetrics
(
objective
,
metric
);
std
::
transform
(
value
.
begin
(),
value
.
end
(),
value
.
begin
(),
Common
::
tolower
);
ParseMetrics
(
value
,
metric
);
}
}
}
}
}
...
@@ -208,8 +205,8 @@ void Config::Set(const std::unordered_map<std::string, std::string>& params) {
...
@@ -208,8 +205,8 @@ void Config::Set(const std::unordered_map<std::string, std::string>& params) {
GetTaskType
(
params
,
&
task
);
GetTaskType
(
params
,
&
task
);
GetBoostingType
(
params
,
&
boosting
);
GetBoostingType
(
params
,
&
boosting
);
GetMetricType
(
params
,
&
metric
);
GetObjectiveType
(
params
,
&
objective
);
GetObjectiveType
(
params
,
&
objective
);
GetMetricType
(
params
,
objective
,
&
metric
);
GetDeviceType
(
params
,
&
device_type
);
GetDeviceType
(
params
,
&
device_type
);
if
(
device_type
==
std
::
string
(
"cuda"
))
{
if
(
device_type
==
std
::
string
(
"cuda"
))
{
LGBM_config_
::
current_device
=
lgbm_device_cuda
;
LGBM_config_
::
current_device
=
lgbm_device_cuda
;
...
...
tests/python_package_test/test_engine.py
View file @
d130bb19
...
@@ -2029,6 +2029,27 @@ def test_multiple_feval_cv():
...
@@ -2029,6 +2029,27 @@ def test_multiple_feval_cv():
assert
'decreasing_metric-stdv'
in
cv_results
assert
'decreasing_metric-stdv'
in
cv_results
def
test_default_objective_and_metric
():
X
,
y
=
load_breast_cancer
(
return_X_y
=
True
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.2
)
train_dataset
=
lgb
.
Dataset
(
data
=
X_train
,
label
=
y_train
)
validation_dataset
=
lgb
.
Dataset
(
data
=
X_test
,
label
=
y_test
,
reference
=
train_dataset
)
evals_result
=
{}
params
=
{
'verbose'
:
-
1
}
lgb
.
train
(
params
=
params
,
train_set
=
train_dataset
,
valid_sets
=
validation_dataset
,
num_boost_round
=
5
,
callbacks
=
[
lgb
.
record_evaluation
(
evals_result
)]
)
assert
'valid_0'
in
evals_result
assert
len
(
evals_result
[
'valid_0'
])
==
1
assert
'l2'
in
evals_result
[
'valid_0'
]
assert
len
(
evals_result
[
'valid_0'
][
'l2'
])
==
5
@
pytest
.
mark
.
skipif
(
psutil
.
virtual_memory
().
available
/
1024
/
1024
/
1024
<
3
,
reason
=
'not enough RAM'
)
@
pytest
.
mark
.
skipif
(
psutil
.
virtual_memory
().
available
/
1024
/
1024
/
1024
<
3
,
reason
=
'not enough RAM'
)
def
test_model_size
():
def
test_model_size
():
X
,
y
=
load_boston
(
return_X_y
=
True
)
X
,
y
=
load_boston
(
return_X_y
=
True
)
...
...
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