Skip to content

Commit

Permalink
[python-package] Rename cvfolds variable into cvbooster in `engin…
Browse files Browse the repository at this point in the history
…e.cv` function (#6762)
  • Loading branch information
ClaudioSalvatoreArcidiacono authored Dec 17, 2024
1 parent 480600b commit 4feee28
Showing 1 changed file with 10 additions and 10 deletions.
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)

0 comments on commit 4feee28

Please sign in to comment.