Skip to content

Add sample_weight fit param for Pipeline #18159

@rth

Description

@rth

Currently Pipeline doesn't support the sample_weight fit param. It fails with,

ValueError: Pipeline.fit does not accept the sample_weights parameter. You can pass parameters to
specific steps of your pipeline using the stepname__parameter format, e.g.
 `Pipeline.fit(X, y, logisticregression__sample_weight=sample_weight)`.

passing the sample weight as logisticregression__sample_weight is annoying because it's too strongly coupled with the pipeline step names. This means that this code would break if a different estimator is used in the pipeline or else one need to use pipeline steps independent of the estimator used. In any case pipelines constructed with make_pipeline would break.

I haven't followed the sample props discussion in detail #4497 but is there anything preventing from adding a sample_weight parameter to the pipeline and doing one of the following?

  1. either pass it to the last estimator.
  2. or pass it to all estimators that support sample weights in the pipeline (not sure if there are many transformers with sample weights). Raise an warning error if none support it.

The case 1. would already likely address most use cases. Are there drawbacks in doing this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions