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
3f5b3135
Unverified
Commit
3f5b3135
authored
Dec 29, 2017
by
Guolin Ke
Committed by
GitHub
Dec 29, 2017
Browse files
[python] avoid to set all weight to 1. (#1152)
* avoid to set all weight to 1. * fix valid_class_weight
parent
42710827
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+2
-0
python-package/lightgbm/sklearn.py
python-package/lightgbm/sklearn.py
+12
-10
No files found.
python-package/lightgbm/basic.py
View file @
3f5b3135
...
...
@@ -1105,6 +1105,8 @@ class Dataset(object):
weight : list, numpy array or None
Weight to be set for each data point.
"""
if
weight
is
not
None
and
np
.
all
(
weight
==
1
):
weight
=
None
self
.
weight
=
weight
if
self
.
handle
is
not
None
and
weight
is
not
None
:
weight
=
list_to_1d_numpy
(
weight
,
name
=
'weight'
)
...
...
python-package/lightgbm/sklearn.py
View file @
3f5b3135
...
...
@@ -418,6 +418,7 @@ class LGBMModel(_LGBMModelBase):
X
,
y
=
_LGBMCheckXY
(
X
,
y
,
accept_sparse
=
True
,
force_all_finite
=
False
,
ensure_min_samples
=
2
)
_LGBMCheckConsistentLength
(
X
,
y
,
sample_weight
)
if
self
.
class_weight
is
not
None
:
class_sample_weight
=
_LGBMComputeSampleWeight
(
self
.
class_weight
,
y
)
if
sample_weight
is
None
or
len
(
sample_weight
)
==
0
:
sample_weight
=
class_sample_weight
...
...
@@ -452,6 +453,7 @@ class LGBMModel(_LGBMModelBase):
else
:
raise
TypeError
(
'eval_sample_weight, eval_class_weight, eval_init_score, and eval_group should be dict or list'
)
valid_weight
=
get_meta_data
(
eval_sample_weight
,
i
)
if
get_meta_data
(
eval_class_weight
,
i
)
is
not
None
:
valid_class_sample_weight
=
_LGBMComputeSampleWeight
(
get_meta_data
(
eval_class_weight
,
i
),
valid_data
[
1
])
if
valid_weight
is
None
or
len
(
valid_weight
)
==
0
:
valid_weight
=
valid_class_sample_weight
...
...
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