Skip to content

FIX Validate estimators in Voting{Classifier,Regressor}#30649

Merged
lesteve merged 5 commits into
scikit-learn:mainfrom
thomasjpfan:validate_voting_classifier
Jan 21, 2025
Merged

FIX Validate estimators in Voting{Classifier,Regressor}#30649
lesteve merged 5 commits into
scikit-learn:mainfrom
thomasjpfan:validate_voting_classifier

Conversation

@thomasjpfan
Copy link
Copy Markdown
Member

Reference Issues/PRs

Fixes #30622

What does this implement/fix? Explain your changes.

This PR adds a little more validation to make sure estimators is correct in VotingClassifer and VotingRegressor.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 15, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 56c8cad. Link to the linter CI: here

Copy link
Copy Markdown
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM. Thanks @thomasjpfan

Comment thread doc/whats_new/upcoming_changes/sklearn.ensemble/30649.fix.rst Outdated
Co-authored-by: Omar Salman <omar.salman2007@gmail.com>
@OmarManzoor OmarManzoor added Quick Review For PRs that are quick to review Waiting for Second Reviewer First reviewer is done, need a second one! labels Jan 17, 2025
Comment thread sklearn/ensemble/_base.py Outdated
def _validate_estimators(self):
if len(self.estimators) == 0:
if len(self.estimators) == 0 or not all(
isinstance(item, tuple) and isinstance(item[0], str)
Copy link
Copy Markdown
Member

@lesteve lesteve Jan 17, 2025

Choose a reason for hiding this comment

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

Not sure how much we care, but the previous code was working fine with lists rather than tuple and with this PR it would be an error, i.e. when using estimators=[['name', LogisticRegression()]] rather than estimators=[('name', LogisticRegression())]

I guess this is documented as a list of tuples but you never know people may be using list of lists in the wild ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm +1 to silently allow lists as well.

For instance in Pipeling, ColumnTransformer, ... we silently allow tuples in addition to lists.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated to allow list in: 56c8cad (#30649)

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Jan 21, 2025

Thanks, let's merge this one!

@lesteve lesteve merged commit f09c7d9 into scikit-learn:main Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ensemble Quick Review For PRs that are quick to review Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate estimators argument of VotingClassifier

4 participants