Skip to content

improve error message when passing sample_weight to Pipeline #13534

Closed

Description

@jnothman

Many estimators take a parameter named sample_weight. Pipeline does not, since it wants its fit parameters to be prefixed by the step name with a __ delimiter:

>>> from sklearn.pipeline import make_pipeline
>>> from sklearn.linear_model import LogisticRegression
>>> clf = make_pipeline(LogisticRegression())
>>> clf.fit([[0], [0]], [0, 1], logisticregression__sample_weight=[1, 1])
Pipeline(memory=None,
     steps=[('logisticregression', LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,
          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,
          verbose=0, warm_start=False))])
>>> clf.fit([[0], [0]], [0, 1], sample_weight=[1, 1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/n/schwafs/home/joel/miniconda3/envs/scipy3k/lib/python3.6/site-packages/sklearn/pipeline.py", line 248, in fit
    Xt, fit_params = self._fit(X, y, **fit_params)
  File "/n/schwafs/home/joel/miniconda3/envs/scipy3k/lib/python3.6/site-packages/sklearn/pipeline.py", line 197, in _fit
    step, param = pname.split('__', 1)
ValueError: not enough values to unpack (expected 2, got 1)

This error message is not friendly enough. It should explicitly describe the correct format for passing sample_weight to a step in a Pipeline.

Activity

  1. added
    Easy
    good first issue
    on Mar 27, 2019
  2. jnothman commented on Mar 27, 2019

    @jnothman
    MemberAuthor

    There is some code in gradient boosting that checks for the current error message, so that should be updated to reflect a changed error message too.

    (Arguably, this should be a TypeError, not a ValueError, since the user has passed the wrong parameter names, but I'm ambivalent to whether we fix that.)

  3. okz12 commented on Mar 28, 2019

    @okz12
    Contributor

    I'd like to take this issue.

  4. jnothman commented on Mar 28, 2019

    @jnothman
    MemberAuthor
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

    Easygood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions