Skip to content

RFC Defining the auto-request strategy for scikit-learn estimators / sample_weight handling #34901

Closed

Description

@StefanieSenger

Warning

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 #31413 soon 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:

class XYZEstimator(BaseEstimator):

    def get_metadata_routing(self):
        ...
        requests.fit.add_auto_request("sample_weight") # <--- one-liner to add auto-requests
        ...

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.

Activity

  1. added
    Needs Triage
    on Sep 7, 2026
  2. added
    Needs Investigation
    and removed
    Needs Triage
    on Sep 7, 2026
  3. 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
  4. ogrisel commented on Sep 8, 2026

    @ogrisel
    Member

    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.

  5. StefanieSenger commented on Sep 9, 2026

    @StefanieSenger
    MemberAuthor

    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.)

  6. added
    Metadata Routing
    on Sep 9, 2026
  7. 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
  8. jeremiedbb commented on Sep 10, 2026

    @jeremiedbb
    Member

    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).

    +1

  9. StefanieSenger commented on Oct 7, 2026

    @StefanieSenger
    MemberAuthor

    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.

  10. StefanieSenger commented on Oct 13, 2026

    @StefanieSenger
    MemberAuthor

    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.

    Edit: Done

  11. StefanieSenger commented on Oct 15, 2026

    @StefanieSenger
    MemberAuthor

    @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.

  12. added this to the 1.10 milestone on Oct 15, 2026
  13. StefanieSenger commented on Oct 15, 2026

    @StefanieSenger
    MemberAuthor

    @everyone_follwing_this_issue: The cut-off date for 1.10 will be November 2nd (and my personal one is next Friday).

  14. StefanieSenger commented on Oct 21, 2026

    @StefanieSenger
    MemberAuthor

    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:

    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)

  15. StefanieSenger commented on Nov 6, 2026

    @StefanieSenger
    MemberAuthor

    Everything has been merged and auto-requests are fully available.
    I close this issue now.

  16. moved this from Todo to Done in Labson Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Metadata RoutingNeeds InvestigationNeeds workRFC

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions