8000 FEAT add SLEP006 with a feature flag by adrinjalali · Pull Request #26103 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

FEAT add SLEP006 with a feature flag #26103

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
merged 11 commits into from
Apr 17, 2023

Conversation

adrinjalali
Copy link
Member
@adrinjalali adrinjalali commented Apr 5, 2023

This PR adds a enable_metadata_routing flag as a global configuration, which is False by default.

A good way to review this PR is to compare some of the files with main instead of sample-props.

test_calibration.py and test_multioutput.py are copied from main here, so the diff here is only compared to sample-props branch, and this PR roles back previous changes to these files.

towards: #26045

@adrinjalali adrinjalali changed the title MNT remove backward compatibility from meta-estimators FEAT add SLEP006 with a feature flag Apr 5, 2023
Comment on lines -529 to -533
# the fit method already accepts everything, therefore we don't
# specify parameters. The value passed to ``child`` needs to be the
# same as what's passed to ``add`` above, in this case
# `"estimator"`.
.warn_on(child="estimator", method="fit", params=None)
Copy link
Member Author

Choose a reason for hiding this comment

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

we don't need to be backward compatible now when the feature flag is on, so these lines are removed.

Comment on lines -162 to -165
"warns_on": {
"fit": ["sample_weight", "metadata"],
"partial_fit": ["sample_weight"],
},
Copy link
Member Author

Choose a reason for hiding this comment

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

removing these and corresponding tests since we don't deal with backward compatibility now.

@adrinjalali adrinjalali marked this pull request as ready for review April 6, 2023 12:34
@glemaitre glemaitre self-requested a review April 6, 2023 15:14
Copy link
Member
@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

The changes looks good. In a subsequent PR, I think that we should have a way to test both legacy weighting and the new metadata routing at least in the common test.

@@ -391,13 +391,6 @@ def _get_check_estimator_ids(obj):
return re.sub(r"\s", "", str(obj))


def _weighted(estimator):
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 wondering if a subsequent PR, we could have a way to test the legacy and new way:

SKLEARN_METADATA_ROUTING="enable" pytest sklearn/test/test_common.py

and then have two constructor selected depending on the config.

Common test could be quite useful to catch up some bugs.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah there can be some tests in common tests, happy to work on it on a subsequent PR (but probably not a blocker to merge sample-props into main).

@@ -121,15 +126,26 @@ def partial_fit(self, X, y, classes=None, sample_weight=None, **partial_fit_para
weights.

**partial_fit_params : dict of str -> object
Copy link
Member

Choose a reason for hiding this comment

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

For reviewer: This parameter was added in sample_props branch.

)

if sample_weight is not None:
kwargs["sample_weight"] = sample_weight
Copy link
Member

Choose a reason for hiding this comment

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

I was about to say that we modify a mutable here and it should be safer to copy. However, now I see that we pass **kwargs and not kwargs so it should be fine.

SGDRegressor,
QuantileRegressor,
)
from sklearn.linear_model import Lasso
Copy link
Member

Choose a reason for hiding this comment

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

I would like so much to have isort to avoid thinking about those changes :)

Copy link
Member Author

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Right now we basically test all the old routing in our tests, and we have dedicated tests for the new routing. But we can certainly work on some tests for common tests, and have a list of meta estimators for which they fail.

routed_params = process_routing(
obj=self, method="fit", other_params=fit_params, sample_weight=sample_weight
)
if _routing_enabled():
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe worth a PR then :P

@@ -391,13 +391,6 @@ def _get_check_estimator_ids(obj):
return re.sub(r"\s", "", str(obj))


def _weighted(estimator):
Copy link
Member Author

Choose a reason for hiding this comment

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

yeah there can be some tests in common tests, happy to work on it on a subsequent PR (but probably not a blocker to merge sample-props into main).

Copy link
Member
@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @adrinjalali

Copy link
Member
@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

I think we should completely get rid of .warn_on. The warning message would not make sense for third party library and we won't need it in scikit-learn.

Besides that, looks good to me. But I would need to see the PR against main to decide whether this is mergeable in main as it is or not.

@@ -84,7 +89,7 @@ def _check(self):


class _MultiOutputEstimator(MetaEstimatorMixin, BaseEstimator, metaclass=ABCMeta):
_parameter_constraints = {
_parameter_constraints: dict = {
Copy link
Member

Choose a reason for hiding this comment

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

seems unrelated and unusual in scikit-learn.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd agree, but this one is also not me here, it's from main:

_parameter_constraints: dict = {

Copy link
Member

Choose a reason for hiding this comment

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

mypy stuff

Copy link
Member Author
@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Besides that, looks good to me. But I would need to see the PR against main to decide whether this is mergeable in main as it is or not.

@ogrisel it isn't ready for merge after this. I'll submit another PR once this is merged to prepare the sample-props branch for merge, with all the nits we need to do before merging, after that PR we can review the big PR and merge.

@@ -84,7 +89,7 @@ def _check(self):


class _MultiOutputEstimator(MetaEstimatorMixin, BaseEstimator, metaclass=ABCMeta):
_parameter_constraints = {
_parameter_constraints: dict = {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd agree, but this one is also not me here, it's from main:

_parameter_constraints: dict = {

@glemaitre glemaitre merged commit d2cb8d5 into scikit-learn:sample-props Apr 17, 2023
@adrinjalali adrinjalali deleted the slep6/feature-flag branch April 17, 2023 10:00
@glemaitre
Copy link
Member

Merging since all points had been addressed and the remaining discussion will be linked to another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0