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
51edbda7
Unverified
Commit
51edbda7
authored
Dec 29, 2022
by
James Lamb
Committed by
GitHub
Dec 29, 2022
Browse files
fix feature index in Dataset::AddFeaturesFrom (fixes #5410) (#5650)
parent
42b6322c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
src/io/dataset.cpp
src/io/dataset.cpp
+1
-1
tests/python_package_test/test_basic.py
tests/python_package_test/test_basic.py
+23
-0
No files found.
src/io/dataset.cpp
View file @
51edbda7
...
...
@@ -1495,7 +1495,7 @@ void Dataset::AddFeaturesFrom(Dataset* other) {
other
->
max_bin_by_feature_
,
other
->
num_total_features_
,
-
1
);
num_total_features_
+=
other
->
num_total_features_
;
for
(
size_t
i
=
0
;
i
<
(
other
->
numeric_feature_map_
).
size
();
++
i
)
{
int
feat_ind
=
numeric_feature_map_
[
i
];
int
feat_ind
=
other
->
numeric_feature_map_
[
i
];
if
(
feat_ind
>
-
1
)
{
numeric_feature_map_
.
push_back
(
feat_ind
+
num_numeric_features_
);
}
else
{
...
...
tests/python_package_test/test_basic.py
View file @
51edbda7
...
...
@@ -376,6 +376,29 @@ def test_add_features_from_different_sources():
assert
d1
.
feature_name
==
res_feature_names
def
test_add_features_does_not_fail_if_initial_dataset_has_zero_informative_features
(
capsys
):
arr_a
=
np
.
zeros
((
100
,
1
),
dtype
=
np
.
float32
)
arr_b
=
np
.
random
.
normal
(
size
=
(
100
,
5
))
dataset_a
=
lgb
.
Dataset
(
arr_a
).
construct
()
expected_msg
=
(
'[LightGBM] [Warning] There are no meaningful features which satisfy '
'the provided configuration. Decreasing Dataset parameters min_data_in_bin '
'or min_data_in_leaf and re-constructing Dataset might resolve this warning.
\n
'
)
log_lines
=
capsys
.
readouterr
().
out
assert
expected_msg
in
log_lines
dataset_b
=
lgb
.
Dataset
(
arr_b
).
construct
()
original_handle
=
dataset_a
.
handle
.
value
dataset_a
.
add_features_from
(
dataset_b
)
assert
dataset_a
.
num_feature
()
==
6
assert
dataset_a
.
num_data
()
==
100
assert
dataset_a
.
handle
.
value
==
original_handle
def
test_cegb_affects_behavior
(
tmp_path
):
X
=
np
.
random
.
random
((
100
,
5
))
X
[:,
[
1
,
3
]]
=
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