8000 improve error message when passing sample_weight to Pipeline · Issue #13534 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

improve error message when passing sample_weight to Pipeline #13534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jnothman opened this issue Mar 27, 2019 · 3 comments · Fixed by #13536
Closed

improve error message when passing sample_weight to Pipeline #13534

jnothman opened this issue Mar 27, 2019 · 3 comments · Fixed by #13536
Labels
Easy Well-defined and straightforward way to resolve good first issue Easy with clear instructions to resolve help wanted

Comments

@jnothman
Copy link
Member

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.

@jnothman jnothman added Easy Well-defined and straightforward way to resolve good first issue Easy with clear instructions to resolve help wanted labels Mar 27, 2019
@jnothman
Copy link
Member Author

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

@okz12
Copy link
Contributor
okz12 commented Mar 28, 2019

I'd like to take this issue.

@jnothman
Copy link
Member Author
jnothman commented Mar 28, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy Well-defined and straightforward way to resolve good first issue Easy with clear instructions to resolve help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0