Skip to content

[MRG] Fix bug when warm starting with early stopping in Hist GBDT #15624

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

Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def fit(self, X, y):

# Compute raw predictions
raw_predictions = self._raw_predict(X_binned_train)
if self.do_early_stopping_ and self._use_validation_data:
raw_predictions_val = self._raw_predict(X_binned_val)

if self.do_early_stopping_ and self.scoring != 'loss':
# Compute the subsample set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ def test_warm_start_max_depth(GradientBoosting, X, y):
(HistGradientBoostingClassifier, X_classification, y_classification),
(HistGradientBoostingRegressor, X_regression, y_regression)
])
def test_warm_start_early_stopping(GradientBoosting, X, y):
@pytest.mark.parametrize('scoring', (None, 'loss'))
def test_warm_start_early_stopping(GradientBoosting, X, y, scoring):
# Make sure that early stopping occurs after a small number of iterations
# when fitting a second time with warm starting.

n_iter_no_change = 5
gb = GradientBoosting(
n_iter_no_change=n_iter_no_change, max_iter=10000,
random_state=42, warm_start=True, tol=1e-3
random_state=42, warm_start=True, tol=1e-3, scoring=scoring,
)
gb.fit(X, y)
n_iter_first_fit = gb.n_iter_
Expand Down