Skip to content

Fix for passing pandas series in sample_weights in RidgeCV leading to an error(#5606) #6307

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
wants to merge 3 commits into from
Closed
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
5 changes: 3 additions & 2 deletions sklearn/linear_model/ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,9 @@ def fit(self, X, y, sample_weight=None):
-------
self : Returns self.
"""
X, y = check_X_y(X, y, ['csr', 'csc', 'coo'], dtype=np.float64,
multi_output=True, y_numeric=True)
X, y, sample_weight = check_X_y(X, y, ['csr', 'csc', 'coo'],
dtype=np.float64, multi_output=True, y_numeric=True,
sample_weight=sample_weight)

n_samples, n_features = X.shape

Expand Down
19 changes: 17 additions & 2 deletions sklearn/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from ..exceptions import NonBLASDotWarning as _NonBLASDotWarning
from ..exceptions import NotFittedError as _NotFittedError

NOT_SPECIFIED = object()


@deprecated("DataConversionWarning has been moved into the sklearn.exceptions"
" module. It will not be available here from version 0.19")
Expand Down Expand Up @@ -429,7 +431,7 @@ def check_X_y(X, y, accept_sparse=None, dtype="numeric", order=None,
copy=False, force_all_finite=True, ensure_2d=True,
allow_nd=False, multi_output=False, ensure_min_samples=1,
ensure_min_features=1, y_numeric=False,
warn_on_dtype=False, estimator=None):
warn_on_dtype=False, estimator=None, sample_weight=NOT_SPECIFIED):
"""Input validation for standard estimators.

Checks X and y for consistent length, enforces X 2d and y 1d.
Expand Down Expand Up @@ -503,6 +505,10 @@ def check_X_y(X, y, accept_sparse=None, dtype="numeric", order=None,
estimator : str or estimator instance (default=None)
If passed, include the name of the estimator in warning messages.

sample_weight : nd-array, list
Ensures sample_weight is 1-d.


Returns
-------
X_converted : object
Expand All @@ -525,7 +531,16 @@ def check_X_y(X, y, accept_sparse=None, dtype="numeric", order=None,

check_consistent_length(X, y)

return X, y
if sample_weight is NOT_SPECIFIED:
return X, y

elif sample_weight is None:
return X, y, sample_weight

else:
sample_weight = check_array(sample_weight, ensure_2d=False)
check_consistent_length(y, sample_weight)
return X, y, sample_weight


def column_or_1d(y, warn=False):
Expand Down