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
7d582dd8
Unverified
Commit
7d582dd8
authored
May 21, 2025
by
Nick Miller
Committed by
GitHub
May 21, 2025
Browse files
[python-package] Add specific error messages to `test_engine` (#6925)
parent
1ff120cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
5 deletions
+8
-5
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+8
-5
No files found.
tests/python_package_test/test_engine.py
View file @
7d582dd8
...
...
@@ -2868,10 +2868,13 @@ def test_metrics():
assert
len
(
res
)
==
2
assert
"valid error-mean"
in
res
# multiclass metric alias with custom one with invalid class_num
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
):
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"Multiclass objective and metrics don't match"
):
get_cv_result
(
params_dummy_obj_class_1_verbose
,
metrics
=
obj_multi_alias
,
feval
=
constant_metric
)
# multiclass default metric without num_class
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
):
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"Number of classes should be specified and greater than 1 for multiclass training"
,
):
get_cv_result
(
params_obj_verbose
)
for
metric_multi_alias
in
obj_multi_aliases
+
[
"multi_logloss"
]:
# multiclass metric alias
...
...
@@ -2883,11 +2886,11 @@ def test_metrics():
assert
len
(
res
)
==
2
assert
"valid multi_error-mean"
in
res
# non-valid metric for multiclass objective
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
):
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"Multiclass objective and metrics don't match"
):
get_cv_result
(
params_obj_class_3_verbose
,
metrics
=
"binary_logloss"
)
params_class_3_verbose
=
{
"num_class"
:
3
,
"verbose"
:
-
1
}
# non-default num_class for default objective
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
):
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"Number of classes must be 1 for non-multiclass training"
):
get_cv_result
(
params_class_3_verbose
)
# no metric with non-default num_class for custom objective
res
=
get_cv_result
(
params_dummy_obj_class_3_verbose
)
...
...
@@ -2902,7 +2905,7 @@ def test_metrics():
assert
len
(
res
)
==
2
assert
"valid multi_error-mean"
in
res
# binary metric with non-default num_class for custom objective
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
):
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"Multiclass objective and metrics don't match"
):
get_cv_result
(
params_dummy_obj_class_3_verbose
,
metrics
=
"binary_error"
)
...
...
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