@@ -269,9 +269,10 @@ def ridge_regression(X, y, alpha, sample_weight=None, solver='auto',
269
269
iteration performed by the solver.
270
270
271
271
return_intercept : boolean, default False
272
- If True, the method also returns the intercept, and the solver
273
- is automatically changed to 'sag'. This is only a temporary fix
274
- for fitting the intercept with sparse data.
272
+ If True and if X is sparse, the method also returns the intercept,
273
+ and the solver is automatically changed to 'sag'. This is only a
274
+ temporary fix for fitting the intercept with sparse data. For dense
275
+ data, use sklearn.linear_model.center_data before your regression.
275
276
276
277
Returns
277
278
-------
@@ -282,11 +283,15 @@ def ridge_regression(X, y, alpha, sample_weight=None, solver='auto',
282
283
The actual number of iteration performed by the solver.
283
284
Only returned if `return_n_iter` is True.
284
285
286
+ intercept : float or array, shape = [n_targets]
287
+ The intercept of the model. Only returned if `return_intercept`
288
+ is True and if X is a scipy sparse array.
289
+
285
290
Notes
286
291
-----
287
292
This function won't compute the intercept.
288
293
"""
289
- if return_intercept and solver != 'sag' :
294
+ if return_intercept and sparse . issparse ( X ) and solver != 'sag' :
290
295
warnings .warn ("In Ridge, only 'sag' solver can currently fit the "
291
296
"intercept when X is sparse. Solver has been "
292
297
"automatically changed into 'sag'." )
@@ -451,6 +456,7 @@ def fit(self, X, y, sample_weight=None):
451
456
X , y , self .fit_intercept , self .normalize , self .copy_X ,
452
457
sample_weight = sample_weight )
453
458
459
+ # temporary fix for fitting the intercept with sparse data using 'sag'
454
460
if sparse .issparse (X ) and self .fit_intercept :
455
461
self .coef_ , self .n_iter_ , self .intercept_ = ridge_regression (
456
462
X , y , alpha = self .alpha , sample_weight = sample_weight ,
0 commit comments