Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python-package] Rename cvfolds variable into cvbooster in engine.cv function #6762

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions python-package/lightgbm/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def cv(
train_set._update_params(params)._set_predictor(predictor)

results = defaultdict(list)
cvfolds = _make_n_folds(
cvbooster = _make_n_folds(
full_data=train_set,
folds=folds,
nfold=nfold,
Expand Down Expand Up @@ -802,24 +802,24 @@ def cv(
for cb in callbacks_before_iter:
cb(
callback.CallbackEnv(
model=cvfolds,
model=cvbooster,
params=params,
iteration=i,
begin_iteration=0,
end_iteration=num_boost_round,
evaluation_result_list=None,
)
)
cvfolds.update(fobj=fobj) # type: ignore[call-arg]
res = _agg_cv_result(cvfolds.eval_valid(feval)) # type: ignore[call-arg]
cvbooster.update(fobj=fobj) # type: ignore[call-arg]
res = _agg_cv_result(cvbooster.eval_valid(feval)) # type: ignore[call-arg]
for _, key, mean, _, std in res:
results[f"{key}-mean"].append(mean)
results[f"{key}-stdv"].append(std)
try:
for cb in callbacks_after_iter:
cb(
callback.CallbackEnv(
model=cvfolds,
model=cvbooster,
params=params,
iteration=i,
begin_iteration=0,
Expand All @@ -828,14 +828,14 @@ def cv(
)
)
except callback.EarlyStopException as earlyStopException:
cvfolds.best_iteration = earlyStopException.best_iteration + 1
for bst in cvfolds.boosters:
bst.best_iteration = cvfolds.best_iteration
cvbooster.best_iteration = earlyStopException.best_iteration + 1
for bst in cvbooster.boosters:
bst.best_iteration = cvbooster.best_iteration
for k in results:
results[k] = results[k][: cvfolds.best_iteration]
results[k] = results[k][: cvbooster.best_iteration]
break

if return_cvbooster:
results["cvbooster"] = cvfolds # type: ignore[assignment]
results["cvbooster"] = cvbooster # type: ignore[assignment]

return dict(results)
Loading