Repository navigation
MNT Refactor auto-requests for validation sets - #35147
StefanieSenger wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
@StefanieSenger should we add tests for the X_val, y_val, sample_weight_val auto requests ?
We certainly can, but if I'm happy to still all |
|
I also think the validation set auto requests should be tested. If not tested, a typo here like |
ogrisel
left a comment
There was a problem hiding this comment.
Here is some extra feedback beyond the missing test discussed above.
| if "sample_weight_val" in method_request.requests: | ||
| method_request.add_auto_request("sample_weight_val") |
There was a problem hiding this comment.
Shouldn't we check that both _auto_request_sample_weight and _auto_request_validation_set are true at the same time before auto requesting "sample_weight_val"?
| if "sample_weight_val" in method_request.requests: | |
| method_request.add_auto_request("sample_weight_val") | |
| if ( | |
| getattr(self, "_auto_request_sample_weight", False) | |
| and "sample_weight_val" in method_request.requests | |
| ): | |
| method_request.add_auto_request("sample_weight_val") |
There was a problem hiding this comment.
I am not sure. In scikit-learn we always auto-request both anyway (if they are present in the signature).
Adding this condition would constrain third party estimators, if their developers set _auto_request_sample_weight = False and keep _auto_request_validation_set = True. I'd tend to have them be responsible on how to use these attributes and not create an interdependence between them that we then need to document.
What do you think?
| # classes do not set this attribute (even if they inherit from `BaseEstimator`) | ||
| # but they can opt in by inheriting from `AutoRequestMixin`. | ||
| if cls.__module__.startswith("sklearn.") and any( | ||
| base.__name__ == "BaseEstimator" for base in cls.__mro__[1:] |
There was a problem hiding this comment.
Wouldn't issubclass(base, BaseEstimator) work here?
There was a problem hiding this comment.
Theoretically I think it should work, but if I try I get a nasty circular import error upon from sklearn.base import BaseEstimator because these two modules import each other. We could move the attribute creation (cls._auto_request_sample_weight = True and cls._auto_request_validation_set = True) into BaseEstimator to circumvent this, but then the auto-request setup is spread across different classes and I would rather leave it as is.
StefanieSenger
left a comment
There was a problem hiding this comment.
Thanks for your reviews, @antoinebaker, @FrancoisPgm and @ogrisel.
I have added the test cases for validation sets into sklearn/tests/test_base.py and replied to the open questions. Happy to do any adjustments.
Reference Issues/PRs
towards #34901
What does this implement/fix? Explain your changes.
This is a re-factor of #34957, now we have #34966 merged.
It does not change any API or functionality (and thus isn't urgent)
It only changes the explicitness of auto-requesting validation sets on HGB*. With this PR, any estimator that newly accepts
X_val,y_val, ... will expose an auto-request ifenable_metadata_auto_requests=True(but we can opt out by setting it toFalseexplicitly if we want to).The advantage would be that in
process_routing, we have one central place where we add all the auto-request setting and we would not need to overwrite theget_metadata_routing()methods of all the estimators that will in future accept validation sets.AI usage disclosure
I used AI assistance for: