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
b1facf50
Unverified
Commit
b1facf50
authored
Nov 08, 2021
by
Zhiyuan He
Committed by
GitHub
Nov 08, 2021
Browse files
Suppress categorical warning (fixes #3379)
parent
858cc0a7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
8 deletions
+36
-8
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+36
-6
tests/python_package_test/test_utilities.py
tests/python_package_test/test_utilities.py
+0
-2
No files found.
python-package/lightgbm/basic.py
View file @
b1facf50
...
...
@@ -1510,6 +1510,8 @@ class Dataset:
if
categorical_indices
:
for
cat_alias
in
_ConfigAliases
.
get
(
"categorical_feature"
):
if
cat_alias
in
params
:
# If the params[cat_alias] is equal to categorical_indices, do not report the warning.
if
not
(
isinstance
(
params
[
cat_alias
],
list
)
and
set
(
params
[
cat_alias
])
==
categorical_indices
):
_log_warning
(
f
'
{
cat_alias
}
in param dict is overridden.'
)
params
.
pop
(
cat_alias
,
None
)
params
[
'categorical_column'
]
=
sorted
(
categorical_indices
)
...
...
@@ -1765,6 +1767,32 @@ class Dataset:
ctypes
.
byref
(
self
.
handle
)))
return
self
@
staticmethod
def
_compare_params_for_warning
(
params
,
other_params
):
"""Compare params.
It is only for the warning purpose. Thus some keys are ignored.
Returns
-------
compare_result: bool
If they are equal, return True; Otherwise, return False.
"""
ignore_keys
=
_ConfigAliases
.
get
(
"categorical_feature"
)
if
params
is
None
:
params
=
{}
if
other_params
is
None
:
other_params
=
{}
for
k
in
other_params
:
if
k
not
in
ignore_keys
:
if
k
not
in
params
or
params
[
k
]
!=
other_params
[
k
]:
return
False
for
k
in
params
:
if
k
not
in
ignore_keys
:
if
k
not
in
other_params
or
params
[
k
]
!=
other_params
[
k
]:
return
False
return
True
def
construct
(
self
):
"""Lazy init.
...
...
@@ -1776,7 +1804,9 @@ class Dataset:
if
self
.
handle
is
None
:
if
self
.
reference
is
not
None
:
reference_params
=
self
.
reference
.
get_params
()
if
self
.
get_params
()
!=
reference_params
:
params
=
self
.
get_params
()
if
params
!=
reference_params
:
if
self
.
_compare_params_for_warning
(
params
,
reference_params
)
is
False
:
_log_warning
(
'Overriding the parameters from Reference Dataset.'
)
self
.
_update_params
(
reference_params
)
if
self
.
used_indices
is
None
:
...
...
@@ -2062,9 +2092,9 @@ class Dataset:
self
.
categorical_feature
=
categorical_feature
return
self
.
_free_handle
()
elif
categorical_feature
==
'auto'
:
_log_warning
(
'Using categorical_feature in Dataset.'
)
return
self
else
:
if
self
.
categorical_feature
!=
'auto'
:
_log_warning
(
'categorical_feature in Dataset is overridden.
\n
'
f
'New categorical_feature is
{
sorted
(
list
(
categorical_feature
))
}
'
)
self
.
categorical_feature
=
categorical_feature
...
...
tests/python_package_test/test_utilities.py
View file @
b1facf50
...
...
@@ -43,8 +43,6 @@ def test_register_logger(tmp_path):
lgb
.
plot_metric
(
eval_records
)
expected_log
=
r
"""
WARNING | categorical_feature in Dataset is overridden.
New categorical_feature is [1]
INFO | [LightGBM] [Warning] There are no meaningful features, as all feature values are constant.
INFO | [LightGBM] [Info] Number of positive: 2, number of negative: 2
INFO | [LightGBM] [Info] Total Bins 0
...
...
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