Skip to content
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

[pull] main from scikit-learn:main #17

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sklearn/ensemble/_weight_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def fit(self, X, y, sample_weight=None):
)

sample_weight = _check_sample_weight(
sample_weight, X, np.float64, copy=True, ensure_non_negative=True
sample_weight, X, dtype=np.float64, copy=True, ensure_non_negative=True
)
sample_weight /= sample_weight.sum()

Expand Down
2 changes: 1 addition & 1 deletion sklearn/tree/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _fit(
)

if sample_weight is not None:
sample_weight = _check_sample_weight(sample_weight, X, DOUBLE)
sample_weight = _check_sample_weight(sample_weight, X, dtype=DOUBLE)

if expanded_class_weight is not None:
if sample_weight is not None:
Expand Down
20 changes: 12 additions & 8 deletions sklearn/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ def _check_psd_eigenvalues(lambdas, enable_warnings=False):


def _check_sample_weight(
sample_weight, X, dtype=None, copy=False, ensure_non_negative=False
sample_weight, X, *, dtype=None, ensure_non_negative=False, copy=False
):
"""Validate sample weights.

Expand All @@ -2144,18 +2144,22 @@ def _check_sample_weight(
X : {ndarray, list, sparse matrix}
Input data.

dtype : dtype, default=None
dtype of the validated `sample_weight`.
If None, and `sample_weight` is an array:

- If `sample_weight.dtype` is one of `{np.float64, np.float32}`,
then the dtype is preserved.
- Else the output has NumPy's default dtype: `np.float64`.

If `dtype` is not `{np.float32, np.float64, None}`, then output will
be `np.float64`.

ensure_non_negative : bool, default=False,
Whether or not the weights are expected to be non-negative.

.. versionadded:: 1.0

dtype : dtype, default=None
dtype of the validated `sample_weight`.
If None, and the input `sample_weight` is an array, the dtype of the
input is preserved; otherwise an array with the default numpy dtype
is be allocated. If `dtype` is not one of `float32`, `float64`,
`None`, the output will be of dtype `float64`.

copy : bool, default=False
If True, a copy of sample_weight will be created.

Expand Down
Loading