8000 FIX temporary fix for #4710 · TomDLT/scikit-learn@e1f9625 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1f9625

Browse files
committed
FIX temporary fix for scikit-learn#4710
1 parent 17a68ac commit e1f9625

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

sklearn/linear_model/ridge.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,8 @@ def ridge_regression(X, y, alpha, sample_weight=None, solver='auto',
313313
raise ValueError("Sample weights must be 1D array or scalar")
314314

315315
if solver != 'sag':
316-
# Sample weight can be implemented via a simple rescaling.
317-
# FIX: In the sparse case, with fit_intercept=True, we cannot
318-
# center the data, so a rescaling is incorrect! See #4710.
319-
# Sag solver can actually handle sample weights without rescaling,
320-
# and can be used as a reference to solve #4710.
316+
# SAG supports sample_weight directly. For other solvers,
317+
# we implement sample_weight via a simple rescaling.
321318
X, y = _rescale_data(X, y, sample_weight)
322319

323320
# There should be either 1 or n_targets penalties
@@ -405,6 +402,13 @@ def fit(self, X, y, sample_weight=None):
405402
X, y, self.fit_intercept, self.normalize, self.copy_X,
406403
sample_weight=sample_weight)
407404

405+
if sparse.issparse(X) and self.fit_intercept:
406+
if self.solver == 'auto':
407+
self.solver = 'sag'
408+
elif self.solver != 'sag':
409+
raise ValueError("Only sag solver can handle sparse data with"
410+
" fit_intercept=True (temp fix for #4710)")
411+
408412
self.coef_ = ridge_regression(X, y,
409413
alpha=self.alpha,
410414
sample_weight=sample_weight,

0 commit comments

Comments
 (0)
0