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

TST Relax test_gradient_boosting_early_stopping #24541

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions sklearn/ensemble/tests/test_gradient_boosting.py
Expand Up @@ -1122,16 +1122,26 @@ def test_gradient_boosting_early_stopping():
)

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
# Check if early_stopping works as expected
for est, tol, early_stop_n_estimators in (
# Check if early_stopping works as expected, that is empirically check that the
# number of estimators is increasing when the tolerance decreases.

# Depending on platforms, the number of fitted estimators might slightly vary.
# Hence, we check for its inclusion in an interval centered in the expected
# number of fitted estimators rather than a strict equality.
delta_early_stop_n_estimators = 2
for est, tol, expected_early_stop_n_estimators in (
(gbc, 1e-1, 28),
(gbr, 1e-1, 13),
(gbc, 1e-3, 70),
(gbr, 1e-3, 28),
):
est.set_params(tol=tol)
est.fit(X_train, y_train)
assert est.n_estimators_ == early_stop_n_estimators
assert (
expected_early_stop_n_estimators - delta_early_stop_n_estimators
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be enough to have an upper bound with a less-than-operator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don't get here is why Python 3.11 would trigger this issue while other Windows builds are working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just follow the description of the test and simply check the following ?
gbc(tol=1e-1).fit(X, y).n_estimators_ < gbc(tol=1e-3).fit(X, y).n_estimators_

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c47bbbd.

<= est.n_estimators_
<= expected_early_stop_n_estimators + delta_early_stop_n_estimators
)
assert est.score(X_test, y_test) > 0.7

# Without early stopping
Expand Down