8000 DOC update docstring and warning · scikit-learn/scikit-learn@db49cdd · GitHub
[go: up one dir, main page]

Skip to content

Commit db49cdd

Browse files
committed
DOC update docstring and warning
1 parent d972da2 commit db49cdd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sklearn/linear_model/ridge.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ def ridge_regression(X, y, alpha, sample_weight=None, solver='auto',
269269
iteration performed by the solver.
270270
271271
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.
275276
276277
Returns
277278
-------
@@ -282,11 +283,15 @@ def ridge_regression(X, y, alpha, sample_weight=None, solver='auto',
282283
The actual number of iteration performed by the solver.
283284
Only returned if `return_n_iter` is True.
284285
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+
285290
Notes
286291
-----
287292
This function won't compute the intercept.
288293
"""
289-
if return_intercept and solver != 'sag':
294+
if return_intercept and sparse.issparse(X) and solver != 'sag':
290295
warnings.warn("In Ridge, only 'sag' solver can currently fit the "
291296
"intercept when X is sparse. Solver has been "
292297
"automatically changed into 'sag'.")
@@ -451,6 +456,7 @@ def fit(self, X, y, sample_weight=None):
451456
X, y, self.fit_intercept, self.normalize, self.copy_X,
452457
sample_weight=sample_weight)
453458

459+
# temporary fix for fitting the intercept with sparse data using 'sag'
454460
if sparse.issparse(X) and self.fit_intercept:
455461
self.coef_, self.n_iter_, self.intercept_ = ridge_regression(
456462
X, y, alpha=self.alpha, sample_weight=sample_weight,

0 commit comments

Comments
 (0)
0