You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RFC Defining the auto-request strategy for scikit-learn estimators / sample_weight handling #34901
This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.
ACA Where do we want to use sample_weight by default?
With #31413soon to be merged, we have defined the mechanism for the auto-routing strategy in scikit-learn (and for use in third party libraries). It will be easily possible to define per estimator which methods of the estimator will request which metadata if users set set_config(enable_metadata_requests=True). (Context: At one point in the future this setting will become the default, but for now it is opt-in.)
The way to do this is to call add_auto_request inside an estimator's get_metadata_routing method:
The effect of adding an auto-request is that then XYZEstimator.fit() automatically requests and uses sample_weight if the user has passed it into the top-level meta-estimator or cross validation.
This issue is to define the scope of the auto-requests.
We have discussed this in our bi-weekly meeting on pushing the subject of auto-requests and here we want to give everybody who is interested the opportunity to share their ideas on the following questions:
Which metadata should get auto-requested ("sample_weigh", "X_val", "sample_weight_val", custom metadata, other?)
Should we add auto-requests to fit and score everywhere or are there estimators where that doesn't make any sense?
Which type of tests do we need?
My personal take would be to work these questions out in separate POC PRs.
CC @scikit-learn/core-devs for gathering opinions. I'm especially interested in the opinions of the statistically more inclined core devs (since we can figure out the engineering part pretty easily). Happy to discuss this in calls also.
Reacted by Adrin Jalali, Jérémie du Boisberranger and Julien Jerphanion
changed the title [-]RFC Defining the auto-routing strategy for scikit-learn estimators[/-][+]RFC Defining the auto-routing strategy for scikit-learn estimators / sample_weight handling[/+]on Sep 7, 2026
I suppose that all public estimator or scorer methods that accept sample_weight, X_val, y_val and sample_weight_val should automatically request those.
I suppose that all public estimator or scorer methods that accept sample_weight, X_val, y_val and sample_weight_val should automatically request those.
From what I understand about this, I agree with this way forward.
X_val, y_val and sample_weight_val are currently only used in Pipeline and HGB. I think it makes sense to always auto-request these where can be consumed. Then later, we can auto-request them while implementing them in the new places (callbacks, other estimators that internally split off a validation set).
Concerning sample_weight, what do you think about pipelines that have transformers and a final estimator, @ogrisel? For instance, StandardScaler.fit can consume sample_weight. Auto-requesting sample_weight everywhere would mean to use it when fitting transformers and the final estimator alike. Is there anything that speaks against it from a statistical standpoint?
Another problem to solve is when a user needs to pass different sample_weight to fit and score (using aliases). How can we make it easy for them to pass aliases (apart from having a good documentation). An idea would be to restrict the naming of the aliases, such as requiring the alias to be sample_weight_score in the case of auto-requesting it. What do you think about this?
Edit: after speaking to @adrinjalali about this, I realise this may not be a problem that we need to solve to make auto-requests work, because calls to fit and score are always separate calls. (And for custom requests set by the user this is already possible since the beginning.)
changed the title [-]RFC Defining the auto-routing strategy for scikit-learn estimators / sample_weight handling[/-][+]RFC Defining the auto-request strategy for scikit-learn estimators / sample_weight handling[/+]on Sep 9, 2026
X_val, y_val and sample_weight_val are currently only used in Pipeline and HGB. I think it makes sense to always auto-request these where can be consumed. Then later, we can auto-request them while implementing them in the new places (callbacks, other estimators that internally split off a validation set).
Since we talked about in the meeting: if enable_metadata_auto_request=True is released as the default setting in 1.10, many of our older tests on metadata routing (those that test if an error is raised if users don't set a request at least) need to be run in the context of enable_metadata_auto_request=False. And we can certainly then remove the with config_context(enable_metadata_auto_requests=True): we have been adding in the PRs referenced in this issue so far.
Little not so we don't forget: Instead of requests.fit.add_auto_request("X_val", "y_val", "sample_weight_val") in HGB*'s get_metadata_routing like we did in #34957, we could also add it in process_routing like we do in #34966. This would be a little re-structuring and doesn't imply a behaviour change.
@adrinjalali brought up that we'd rather support all scikit-learn metadata that is consumed by any method not only sample_weight and validation sets. Do we want this in the 1.10 release?
We certainly need an explicit list of param names for this. (I didn't do any research yet on which those would be.)
I suppose we can then add those inside the new section in process_routing added by #34966.
Along the way, we could restructure this part a bit, so we iterate SIMPLE_METHODS more elegantly using the list of param names that we want to auto-request.
Happy to review if someone wants to take care of it.
@antoinebaker will open a PR to change the default value of enable_metadata_auto_requests from False to True, which will need quick reviews, so it gets merged by November 2nd.
When all this is done, the feature is fully in and we can use it for the release highlights ("Metadata routing just got so much easier to use, because users don't need to set requests for most use cases...."). As an inspiration, we have a new example demonstrating auto-requests and we have new user docs and new developer docs for the auto-request feature.
Activity
[-]RFC Defining the auto-routing strategy for scikit-learn estimators[/-][+]RFC Defining the auto-routing strategy for scikit-learn estimators / sample_weight handling[/+]ogrisel commentedon Sep 8, 2026
I suppose that all public estimator or scorer methods that accept
sample_weight,X_val,y_valandsample_weight_valshould automatically request those.StefanieSenger commentedon Sep 9, 2026
From what I understand about this, I agree with this way forward.
X_val,y_valandsample_weight_valare currently only used in Pipeline and HGB. I think it makes sense to always auto-request these where can be consumed. Then later, we can auto-request them while implementing them in the new places (callbacks, other estimators that internally split off a validation set).Concerning
sample_weight, what do you think about pipelines that have transformers and a final estimator, @ogrisel? For instance,StandardScaler.fitcan consumesample_weight. Auto-requestingsample_weighteverywhere would mean to use it when fitting transformers and the final estimator alike. Is there anything that speaks against it from a statistical standpoint?Another problem to solve is when a user needs to pass differentsample_weighttofitandscore(using aliases). How can we make it easy for them to pass aliases (apart from having a good documentation). An idea would be to restrict the naming of the aliases, such as requiring the alias to besample_weight_scorein the case of auto-requesting it. What do you think about this?Edit: after speaking to @adrinjalali about this, I realise this may not be a problem that we need to solve to make auto-requests work, because calls to
fitandscoreare always separate calls. (And for custom requests set by the user this is already possible since the beginning.)[-]RFC Defining the auto-routing strategy for scikit-learn estimators / sample_weight handling[/-][+]RFC Defining the auto-request strategy for scikit-learn estimators / sample_weight handling[/+]jeremiedbb commentedon Sep 10, 2026
+1
StefanieSenger commentedon Oct 7, 2026
Since we talked about in the meeting: if
enable_metadata_auto_request=Trueis released as the default setting in 1.10, many of our older tests on metadata routing (those that test if an error is raised if users don't set a request at least) need to be run in the context ofenable_metadata_auto_request=False. And we can certainly then remove thewith config_context(enable_metadata_auto_requests=True):we have been adding in the PRs referenced in this issue so far.StefanieSenger commentedon Oct 13, 2026
Little not so we don't forget: Instead of
requests.fit.add_auto_request("X_val", "y_val", "sample_weight_val")in HGB*'s get_metadata_routing like we did in #34957, we could also add it inprocess_routinglike we do in #34966. This would be a little re-structuring and doesn't imply a behaviour change.Edit: Done
StefanieSenger commentedon Oct 15, 2026
@adrinjalali brought up that we'd rather support all scikit-learn metadata that is consumed by any method not only
sample_weightand validation sets. Do we want this in the 1.10 release?We certainly need an explicit list of param names for this. (I didn't do any research yet on which those would be.)
I suppose we can then add those inside the new section in
process_routingadded by #34966.Along the way, we could restructure this part a bit, so we iterate
SIMPLE_METHODSmore elegantly using the list of param names that we want to auto-request.Happy to review if someone wants to take care of it.
StefanieSenger commentedon Oct 15, 2026
@everyone_follwing_this_issue: The cut-off date for 1.10 will be November 2nd (and my personal one is next Friday).
StefanieSenger commentedon Oct 21, 2026
Summing up from the meeting, which is relevant for the release planning (CC @jeremiedbb):
We have 4 remaining PRs with mostly 2 approvals already and they should be merged pretty soon:
ENH Auto-requesting
sample_weighton meta-estimators that also consume it #35095ENH Auto-requesting
sample_weighton scorers #35099DOC Add information on
sample_weightauto-routing to glossary and user guide #35111DOC Add example on validation set routing #35144
@antoinebaker will open a PR to change the default value of
enable_metadata_auto_requestsfromFalsetoTrue, which will need quick reviews, so it gets merged by November 2nd.When all this is done, the feature is fully in and we can use it for the release highlights ("Metadata routing just got so much easier to use, because users don't need to set requests for most use cases...."). As an inspiration, we have a new example demonstrating auto-requests and we have new user docs and new developer docs for the auto-request feature.
(Not time critical for the release: #35147)
StefanieSenger commentedon Nov 6, 2026
Everything has been merged and auto-requests are fully available.
I close this issue now.