Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Incorrect error message in _check_sample_weight #31712

Open
@lucyleeow

Description

@lucyleeow

Noticed while working on: #31701

_check_sample_weight gives the following error message:

if sample_weight.ndim != 1:
raise ValueError("Sample weights must be 1D array or scalar")

I don't think sample weights can ever be a scalar. Indeed later we check:

if sample_weight.shape != (n_samples,):
raise ValueError(
"sample_weight.shape == {}, expected {}!".format(
sample_weight.shape, (n_samples,)

So it actually can't be a scalar.

Just to be sure I searched for "weight :" and "weights :" in our docstrings and found that we always ask for and ndarray for sample_weights.

For clustering weights is a string or callable. In the times where weights can be a scalar (e.g., in VotingRegressor or 'class_weights', we never use _check_sample_weight.)

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