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
ca172488
Unverified
Commit
ca172488
authored
Feb 25, 2023
by
James Lamb
Committed by
GitHub
Feb 25, 2023
Browse files
[python-package] remove default values in internal functions (#5730)
parent
6f459cee
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
12 deletions
+12
-12
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+2
-2
python-package/lightgbm/callback.py
python-package/lightgbm/callback.py
+3
-3
python-package/lightgbm/engine.py
python-package/lightgbm/engine.py
+5
-5
python-package/lightgbm/plotting.py
python-package/lightgbm/plotting.py
+2
-2
No files found.
python-package/lightgbm/basic.py
View file @
ca172488
...
@@ -1784,7 +1784,7 @@ class Dataset:
...
@@ -1784,7 +1784,7 @@ class Dataset:
def
__init_from_seqs
(
def
__init_from_seqs
(
self
,
self
,
seqs
:
List
[
Sequence
],
seqs
:
List
[
Sequence
],
ref_dataset
:
Optional
[
_DatasetHandle
]
=
None
ref_dataset
:
Optional
[
_DatasetHandle
]
)
->
"Dataset"
:
)
->
"Dataset"
:
"""
"""
Initialize data from list of Sequence objects.
Initialize data from list of Sequence objects.
...
@@ -4275,7 +4275,7 @@ class Booster:
...
@@ -4275,7 +4275,7 @@ class Booster:
self
,
self
,
data_name
:
str
,
data_name
:
str
,
data_idx
:
int
,
data_idx
:
int
,
feval
:
Optional
[
Union
[
_LGBM_CustomEvalFunction
,
List
[
_LGBM_CustomEvalFunction
]]]
=
None
feval
:
Optional
[
Union
[
_LGBM_CustomEvalFunction
,
List
[
_LGBM_CustomEvalFunction
]]]
)
->
List
[
_LGBM_BoosterEvalMethodResultType
]:
)
->
List
[
_LGBM_BoosterEvalMethodResultType
]:
"""Evaluate training or validation data."""
"""Evaluate training or validation data."""
if
data_idx
>=
self
.
__num_dataset
:
if
data_idx
>=
self
.
__num_dataset
:
...
...
python-package/lightgbm/callback.py
View file @
ca172488
...
@@ -49,7 +49,7 @@ CallbackEnv = collections.namedtuple(
...
@@ -49,7 +49,7 @@ CallbackEnv = collections.namedtuple(
"evaluation_result_list"
])
"evaluation_result_list"
])
def
_format_eval_result
(
value
:
_EvalResultTuple
,
show_stdv
:
bool
=
True
)
->
str
:
def
_format_eval_result
(
value
:
_EvalResultTuple
,
show_stdv
:
bool
)
->
str
:
"""Format metric string."""
"""Format metric string."""
if
len
(
value
)
==
4
:
if
len
(
value
)
==
4
:
return
f
"
{
value
[
0
]
}
's
{
value
[
1
]
}
:
{
value
[
2
]:
g
}
"
return
f
"
{
value
[
0
]
}
's
{
value
[
1
]
}
:
{
value
[
2
]:
g
}
"
...
@@ -338,7 +338,7 @@ class _EarlyStoppingCallback:
...
@@ -338,7 +338,7 @@ class _EarlyStoppingCallback:
def
_final_iteration_check
(
self
,
env
:
CallbackEnv
,
eval_name_splitted
:
List
[
str
],
i
:
int
)
->
None
:
def
_final_iteration_check
(
self
,
env
:
CallbackEnv
,
eval_name_splitted
:
List
[
str
],
i
:
int
)
->
None
:
if
env
.
iteration
==
env
.
end_iteration
-
1
:
if
env
.
iteration
==
env
.
end_iteration
-
1
:
if
self
.
verbose
:
if
self
.
verbose
:
best_score_str
=
'
\t
'
.
join
([
_format_eval_result
(
x
)
for
x
in
self
.
best_score_list
[
i
]])
best_score_str
=
'
\t
'
.
join
([
_format_eval_result
(
x
,
show_stdv
=
True
)
for
x
in
self
.
best_score_list
[
i
]])
_log_info
(
'Did not meet early stopping. '
_log_info
(
'Did not meet early stopping. '
f
'Best iteration is:
\n
[
{
self
.
best_iter
[
i
]
+
1
}
]
\t
{
best_score_str
}
'
)
f
'Best iteration is:
\n
[
{
self
.
best_iter
[
i
]
+
1
}
]
\t
{
best_score_str
}
'
)
if
self
.
first_metric_only
:
if
self
.
first_metric_only
:
...
@@ -364,7 +364,7 @@ class _EarlyStoppingCallback:
...
@@ -364,7 +364,7 @@ class _EarlyStoppingCallback:
continue
# train data for lgb.cv or sklearn wrapper (underlying lgb.train)
continue
# train data for lgb.cv or sklearn wrapper (underlying lgb.train)
elif
env
.
iteration
-
self
.
best_iter
[
i
]
>=
self
.
stopping_rounds
:
elif
env
.
iteration
-
self
.
best_iter
[
i
]
>=
self
.
stopping_rounds
:
if
self
.
verbose
:
if
self
.
verbose
:
eval_result_str
=
'
\t
'
.
join
([
_format_eval_result
(
x
)
for
x
in
self
.
best_score_list
[
i
]])
eval_result_str
=
'
\t
'
.
join
([
_format_eval_result
(
x
,
show_stdv
=
True
)
for
x
in
self
.
best_score_list
[
i
]])
_log_info
(
f
"Early stopping, best iteration is:
\n
[
{
self
.
best_iter
[
i
]
+
1
}
]
\t
{
eval_result_str
}
"
)
_log_info
(
f
"Early stopping, best iteration is:
\n
[
{
self
.
best_iter
[
i
]
+
1
}
]
\t
{
eval_result_str
}
"
)
if
self
.
first_metric_only
:
if
self
.
first_metric_only
:
_log_info
(
f
"Evaluated only:
{
eval_name_splitted
[
-
1
]
}
"
)
_log_info
(
f
"Evaluated only:
{
eval_name_splitted
[
-
1
]
}
"
)
...
...
python-package/lightgbm/engine.py
View file @
ca172488
...
@@ -434,10 +434,10 @@ def _make_n_folds(
...
@@ -434,10 +434,10 @@ def _make_n_folds(
nfold
:
int
,
nfold
:
int
,
params
:
Dict
[
str
,
Any
],
params
:
Dict
[
str
,
Any
],
seed
:
int
,
seed
:
int
,
fpreproc
:
Optional
[
_LGBM_PreprocFunction
]
=
None
,
fpreproc
:
Optional
[
_LGBM_PreprocFunction
],
stratified
:
bool
=
True
,
stratified
:
bool
,
shuffle
:
bool
=
True
,
shuffle
:
bool
,
eval_train_metric
:
bool
=
False
eval_train_metric
:
bool
)
->
CVBooster
:
)
->
CVBooster
:
"""Make a n-fold list of Booster from random indices."""
"""Make a n-fold list of Booster from random indices."""
full_data
=
full_data
.
construct
()
full_data
=
full_data
.
construct
()
...
@@ -685,7 +685,7 @@ def cv(
...
@@ -685,7 +685,7 @@ def cv(
.
set_categorical_feature
(
categorical_feature
)
.
set_categorical_feature
(
categorical_feature
)
results
=
collections
.
defaultdict
(
list
)
results
=
collections
.
defaultdict
(
list
)
cvfolds
=
_make_n_folds
(
train_set
,
folds
=
folds
,
nfold
=
nfold
,
cvfolds
=
_make_n_folds
(
full_data
=
train_set
,
folds
=
folds
,
nfold
=
nfold
,
params
=
params
,
seed
=
seed
,
fpreproc
=
fpreproc
,
params
=
params
,
seed
=
seed
,
fpreproc
=
fpreproc
,
stratified
=
stratified
,
shuffle
=
shuffle
,
stratified
=
stratified
,
shuffle
=
shuffle
,
eval_train_metric
=
eval_train_metric
)
eval_train_metric
=
eval_train_metric
)
...
...
python-package/lightgbm/plotting.py
View file @
ca172488
...
@@ -20,13 +20,13 @@ __all__ = [
...
@@ -20,13 +20,13 @@ __all__ = [
]
]
def
_check_not_tuple_of_2_elements
(
obj
:
Any
,
obj_name
:
str
=
'obj'
)
->
None
:
def
_check_not_tuple_of_2_elements
(
obj
:
Any
,
obj_name
:
str
)
->
None
:
"""Check object is not tuple or does not have 2 elements."""
"""Check object is not tuple or does not have 2 elements."""
if
not
isinstance
(
obj
,
tuple
)
or
len
(
obj
)
!=
2
:
if
not
isinstance
(
obj
,
tuple
)
or
len
(
obj
)
!=
2
:
raise
TypeError
(
f
"
{
obj_name
}
must be a tuple of 2 elements."
)
raise
TypeError
(
f
"
{
obj_name
}
must be a tuple of 2 elements."
)
def
_float2str
(
value
:
float
,
precision
:
Optional
[
int
]
=
None
)
->
str
:
def
_float2str
(
value
:
float
,
precision
:
Optional
[
int
])
->
str
:
return
(
f
"
{
value
:.
{
precision
}
f
}
"
return
(
f
"
{
value
:.
{
precision
}
f
}
"
if
precision
is
not
None
and
not
isinstance
(
value
,
str
)
if
precision
is
not
None
and
not
isinstance
(
value
,
str
)
else
str
(
value
))
else
str
(
value
))
...
...
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