-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FEA Add metadata routing to models that inherit from LinearModelCV #27478
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
FEA Add metadata routing to models that inherit from LinearModelCV #27478
Conversation
@adrinjalali @glemaitre So I fixed the tests and made some adjustments. Could you kindly have a look to see if the overall approach and the corresponding additional test seems fine? If yes then we can add comments to refine this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do routing only for CV and let these classes be consumers of sample_weight
, and the underlying fit
of the sub-estimators don't accept anything other than sample_weight
anyway.
Also need to move the estimators from unsupported to supported in |
Thank you for the feedback @adrinjalali |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
if sample_weight is not None and not has_fit_parameter(self, "sample_weight"): | ||
raise ValueError("Underlying estimator does not support sample weights.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can't happen, can it? if sample weight is not in the signature, it cannot possibly be passed ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MultiTaskElasticNetCV and MultiTaskLassoCV do not support sample_weight currently. But now as we have added **params to both, technically someone can pass sample_weight and if they do and it is unchecked, the code might break unexpectedly. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the thing is, sample_weight
could in theory be used in the cv splitter. So we'd need to check, if the splitter doesn't use it, and the estimator also doesn't support it, then raise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the splitter uses it? Then if we allow sample weight to be passed further than the splitter, the place where we fit the base/child model will pass sample weight as well and that won't work with these estimators. Do we then need to check this where we are using process routing? That is if the splitter.split does not contain sample weight and the estimator doesn't support it as well, then we raise. If the splitter has it but the estimator doesn't support it we set it to None after process routing.
…th don't support, if cv splitter supports but estimator doesn't after routing set sample weight to be None
Parameters to be passed to the CV splitter. | ||
|
||
.. versionadded:: 1.4 | ||
Only available if `enable_metadata_routing=True`. See |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in the other PR, I would suggest to add a reference to set_config
and config_context
to be explicit where enable_metadata_routing
needs to be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need to be done in all places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do this in a separate PR.
or by using the context manager | ||
``with config_context(enable_metadata_routing=True)``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't be advertising the context manager really. It'll cause a lot of issues in this case, if it's enabled in certain places of the code and not in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks @OmarManzoor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as well.
Reference Issues/PRs
Towards #22893
What does this implement/fix? Explain your changes.
Any other comments?
CC: @adrinjalali @glemaitre