Skip to content

Commit

Permalink
[python-package] simplify eval result printing (#6749)
Browse files Browse the repository at this point in the history
Co-authored-by: José Morales <[email protected]>
  • Loading branch information
jameslamb and jmoralez authored Dec 16, 2024
1 parent 8eb3c3c commit 480600b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions python-package/lightgbm/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@ class CallbackEnv:

def _format_eval_result(value: _EvalResultTuple, show_stdv: bool) -> str:
"""Format metric string."""
if len(value) == 4:
return f"{value[0]}'s {value[1]}: {value[2]:g}"
elif len(value) == 5:
if show_stdv:
return f"{value[0]}'s {value[1]}: {value[2]:g} + {value[4]:g}" # type: ignore[misc]
else:
return f"{value[0]}'s {value[1]}: {value[2]:g}"
else:
raise ValueError("Wrong metric value")
dataset_name, metric_name, metric_value, *_ = value
out = f"{dataset_name}'s {metric_name}: {metric_value:g}"
# tuples from cv() sometimes have a 5th item, with standard deviation of
# the evaluation metric (taken over all cross-validation folds)
if show_stdv and len(value) == 5:
out += f" + {value[4]:g}"
return out


class _LogEvaluationCallback:
Expand Down

0 comments on commit 480600b

Please sign in to comment.