Skip to content

FIX avoid race condition in RFECV #23560

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

Closed
Closed
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: 1 addition & 1 deletion sklearn/feature_selection/_rfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def fit(self, X, y, groups=None):
func = delayed(_rfe_single_fit)

scores = parallel(
func(rfe, self.estimator, X, y, train, test, scorer)
func(rfe, clone(self.estimator), X, y, train, test, scorer)
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 construct a non-regression test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @thomasjpfan, I tried to reproduce the error in the original issue but wasn't able to do so :(. Could you help take a look if you got time, thank you!

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if this is where the original error comes from. func = _rfe_single_fit does not actually mutate estimator:

def _rfe_single_fit(rfe, estimator, X, y, train, test, scorer):

_rfe_single_fit only uses estimator for _safe_split and the lambda function has it's own locally scoped `estimator.

lambda estimator, features: _score(
estimator, X_test[:, features], y_test, scorer
),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shall I close this PR for now ? Since it seems not related to the original issue

Copy link
Member

Choose a reason for hiding this comment

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

Yea, I am okay with closing.

for train, test in cv.split(X, y, groups)
)

Expand Down