Skip to content

Improve error message for negative values in sample_weight #20036

Closed
@GMavgo

Description

@GMavgo

With sklearn Version 0.22.1 a linear regression with negative sample weights fails with the following (unclear) error message.
Would be helpful if (e.g. _check_sample_weight) checks for negative weights and raises an appropriate error message.

  File "C:\Users\gm889704\.conda\envs\gm\lib\site-packages\sklearn\pipeline.py", line 354, in fit
    self._final_estimator.fit(Xt, y, **fit_params)

  File "C:\Users\gm889704\.conda\envs\gm\lib\site-packages\sklearn\linear_model\_base.py", line 533, in fit
    linalg.lstsq(X, y)

  File "C:\Users\gm889704\.conda\envs\gm\lib\site-packages\scipy\linalg\basic.py", line 1157, in lstsq
    a1 = _asarray_validated(a, check_finite=check_finite)

  File "C:\Users\gm889704\.conda\envs\gm\lib\site-packages\scipy\_lib\_util.py", line 246, in _asarray_validated
    a = toarray(a)

  File "C:\Users\gm889704\.conda\envs\gm\lib\site-packages\numpy\lib\function_base.py", line 499, in asarray_chkfinite
    "array must not contain infs or NaNs")

ValueError: array must not contain infs or NaNs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions