[python-package] factor out positional indexing for eval result tuples #6748
Description
Description
While working on #3756 and #3867, as well as a variety of early-stopping related things (like #6424), I've found the heavy use of positional indexing and tuple unpacking in early stopping and related code make it really difficult to understand and modify.
For example:
LightGBM/python-package/lightgbm/callback.py
Lines 167 to 176 in 53e0ddf
and:
LightGBM/python-package/lightgbm/callback.py
Lines 410 to 412 in 53e0ddf
I'm opening this issue to track some work I'd like to do to simplify that.
Benefits of this work
Reduces the effort required to finish these:
And to add finer-grained control over early stopping and validation, e.g.:
Approach
I'm planning a series of PRs with the following types of changes:
- unpacking tuples into named variables and using those named variables
- introducing
collections.namedtuple
(docs) where appropriate to allow for named-attribute access while preserving backwards compatibility with the significant amount of custom code in the world relying onlightgbm
expecting tuples for this like custom metrics:
LightGBM/python-package/lightgbm/engine.py
Lines 135 to 138 in 53e0ddf
Notes
Looking at the current state of this code, it's important to remember that when the lightgbm
Python package was first introduced 8+ years ago:
- it supported Python 2.7
dataclasses
was not in the standard library yet (that came in Python 3.7, first release in June 2018)
Activity