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
1a6e6ff9
Unverified
Commit
1a6e6ff9
authored
Sep 13, 2023
by
James Lamb
Committed by
GitHub
Sep 13, 2023
Browse files
[python-package] fix mypy errors related to eval result tuples (#6097)
parent
921479b9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
11 deletions
+13
-11
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+1
-0
python-package/lightgbm/callback.py
python-package/lightgbm/callback.py
+6
-5
python-package/lightgbm/engine.py
python-package/lightgbm/engine.py
+6
-6
No files found.
python-package/lightgbm/basic.py
View file @
1a6e6ff9
...
...
@@ -54,6 +54,7 @@ _ctypes_float_array = Union[
_LGBM_EvalFunctionResultType
=
Tuple
[
str
,
float
,
bool
]
_LGBM_BoosterBestScoreType
=
Dict
[
str
,
Dict
[
str
,
float
]]
_LGBM_BoosterEvalMethodResultType
=
Tuple
[
str
,
str
,
float
,
bool
]
_LGBM_BoosterEvalMethodResultWithStandardDeviationType
=
Tuple
[
str
,
str
,
float
,
bool
,
float
]
_LGBM_CategoricalFeatureConfiguration
=
Union
[
List
[
str
],
List
[
int
],
"Literal['auto']"
]
_LGBM_FeatureNameConfiguration
=
Union
[
List
[
str
],
"Literal['auto']"
]
_LGBM_GroupType
=
Union
[
...
...
python-package/lightgbm/callback.py
View file @
1a6e6ff9
...
...
@@ -3,9 +3,10 @@
from
collections
import
OrderedDict
from
dataclasses
import
dataclass
from
functools
import
partial
from
typing
import
TYPE_CHECKING
,
Any
,
Callable
,
Dict
,
List
,
Optional
,
Tuple
,
Union
from
typing
import
TYPE_CHECKING
,
Any
,
Callable
,
Dict
,
List
,
Optional
,
Union
from
.basic
import
Booster
,
_ConfigAliases
,
_LGBM_BoosterEvalMethodResultType
,
_log_info
,
_log_warning
from
.basic
import
(
Booster
,
_ConfigAliases
,
_LGBM_BoosterEvalMethodResultType
,
_LGBM_BoosterEvalMethodResultWithStandardDeviationType
,
_log_info
,
_log_warning
)
if
TYPE_CHECKING
:
from
.engine
import
CVBooster
...
...
@@ -20,11 +21,11 @@ __all__ = [
_EvalResultDict
=
Dict
[
str
,
Dict
[
str
,
List
[
Any
]]]
_EvalResultTuple
=
Union
[
_LGBM_BoosterEvalMethodResultType
,
Tuple
[
str
,
str
,
float
,
bool
,
float
]
_LGBM_BoosterEvalMethodResultWithStandardDeviationType
]
_ListOfEvalResultTuples
=
Union
[
List
[
_LGBM_BoosterEvalMethodResultType
],
List
[
Tuple
[
str
,
str
,
float
,
bool
,
float
]
]
List
[
_LGBM_BoosterEvalMethodResultWithStandardDeviationType
]
]
...
...
@@ -54,7 +55,7 @@ class CallbackEnv:
iteration
:
int
begin_iteration
:
int
end_iteration
:
int
evaluation_result_list
:
Optional
[
List
[
_LGBM_BoosterEvalMethod
ResultT
ype
]
]
evaluation_result_list
:
Optional
[
_ListOfEval
ResultT
uples
]
def
_format_eval_result
(
value
:
_EvalResultTuple
,
show_stdv
:
bool
)
->
str
:
...
...
python-package/lightgbm/engine.py
View file @
1a6e6ff9
...
...
@@ -11,9 +11,9 @@ import numpy as np
from
.
import
callback
from
.basic
import
(
Booster
,
Dataset
,
LightGBMError
,
_choose_param_value
,
_ConfigAliases
,
_InnerPredictor
,
_LGBM_BoosterEvalMethodResultType
,
_LGBM_
CategoricalFeatureConfigur
ation
,
_LGBM_CustomObjectiveFunction
,
_LGBM_EvalFunctionResultType
,
_LGBM_FeatureNameConfiguration
,
_log_warning
)
_LGBM_BoosterEvalMethodResultType
,
_LGBM_
BoosterEvalMethodResultWithStandardDevi
ation
Type
,
_LGBM_CategoricalFeatureConfiguration
,
_LGBM_CustomObjectiveFunction
,
_LGBM_EvalFunctionResultType
,
_LGBM_FeatureNameConfiguration
,
_log_warning
)
from
.compat
import
SKLEARN_INSTALLED
,
_LGBMBaseCrossValidator
,
_LGBMGroupKFold
,
_LGBMStratifiedKFold
__all__
=
[
...
...
@@ -519,8 +519,8 @@ def _make_n_folds(
def
_agg_cv_result
(
raw_results
:
List
[
List
[
Tuple
[
str
,
str
,
float
,
bool
]
]]
)
->
List
[
Tuple
[
str
,
str
,
float
,
bool
,
float
]
]:
raw_results
:
List
[
List
[
_LGBM_BoosterEvalMethodResultType
]]
)
->
List
[
_LGBM_BoosterEvalMethodResultWithStandardDeviationType
]:
"""Aggregate cross-validation results."""
cvmap
:
Dict
[
str
,
List
[
float
]]
=
OrderedDict
()
metric_type
:
Dict
[
str
,
bool
]
=
{}
...
...
@@ -530,7 +530,7 @@ def _agg_cv_result(
metric_type
[
key
]
=
one_line
[
3
]
cvmap
.
setdefault
(
key
,
[])
cvmap
[
key
].
append
(
one_line
[
2
])
return
[(
'cv_agg'
,
k
,
np
.
mean
(
v
),
metric_type
[
k
],
np
.
std
(
v
))
for
k
,
v
in
cvmap
.
items
()]
return
[(
'cv_agg'
,
k
,
float
(
np
.
mean
(
v
)
)
,
metric_type
[
k
],
float
(
np
.
std
(
v
))
)
for
k
,
v
in
cvmap
.
items
()]
def
cv
(
...
...
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