Skip to content

Commit 10b0480

Browse files
committed
API : set return_models to False by default in path functions in coordinate descent
1 parent d6186e8 commit 10b0480

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

examples/linear_model/plot_lasso_coordinate_descent_path.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,18 @@
3030
eps = 5e-3 # the smaller it is the longer is the path
3131

3232
print("Computing regularization path using the lasso...")
33-
# The return_models parameter sets that lasso_path will return
34-
# the alphas and the coefficients as output, instead of a list
35-
# of models as it does by default. Returning the list of models
36-
# is deprecated and will eventually be removed in 0.15
37-
alphas_lasso, coefs_lasso, _ = lasso_path(X, y, eps, return_models=False,
38-
fit_intercept=False)
33+
alphas_lasso, coefs_lasso, _ = lasso_path(X, y, eps, fit_intercept=False)
3934

4035
print("Computing regularization path using the positive lasso...")
4136
alphas_positive_lasso, coefs_positive_lasso, _ = lasso_path(
42-
X, y, eps, positive=True, return_models=False, fit_intercept=False)
37+
X, y, eps, positive=True, fit_intercept=False)
4338
print("Computing regularization path using the elastic net...")
4439
alphas_enet, coefs_enet, _ = enet_path(
45-
X, y, eps=eps, l1_ratio=0.8, return_models=False, fit_intercept=False)
40+
X, y, eps=eps, l1_ratio=0.8, fit_intercept=False)
4641

4742
print("Computing regularization path using the positve elastic net...")
4843
alphas_positive_enet, coefs_positive_enet, _ = enet_path(
49-
X, y, eps=eps, l1_ratio=0.8, positive=True, return_models=False,
50-
fit_intercept=False)
44+
X, y, eps=eps, l1_ratio=0.8, positive=True, fit_intercept=False)
5145

5246
# Display results
5347

sklearn/linear_model/coordinate_descent.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _alpha_grid(X, y, Xy=None, l1_ratio=1.0, fit_intercept=True,
9090
def lasso_path(X, y, eps=1e-3, n_alphas=100, alphas=None,
9191
precompute='auto', Xy=None, fit_intercept=None,
9292
normalize=None, copy_X=True, coef_init=None,
93-
verbose=False, return_models=True,
93+
verbose=False, return_models=False,
9494
**params):
9595
"""Compute Lasso path with coordinate descent
9696
@@ -200,7 +200,7 @@ def lasso_path(X, y, eps=1e-3, n_alphas=100, alphas=None,
200200
>>> y = np.array([1, 2, 3.1])
201201
>>> # Use lasso_path to compute a coefficient path
202202
>>> _, coef_path, _ = lasso_path(X, y, alphas=[5., 1., .5],
203-
... return_models=False, fit_intercept=False)
203+
... fit_intercept=False)
204204
>>> print(coef_path)
205205
[[ 0. 0. 0.46874778]
206206
[ 0.2159048 0.4425765 0.23689075]]
@@ -236,7 +236,7 @@ def lasso_path(X, y, eps=1e-3, n_alphas=100, alphas=None,
236236
def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,
237237
precompute='auto', Xy=None, fit_intercept=True,
238238
normalize=False, copy_X=True, coef_init=None,
239-
verbose=False, return_models=True,
239+
verbose=False, return_models=False,
240240
**params):
241241
"""Compute Elastic-Net path with coordinate descent
242242
@@ -296,7 +296,7 @@ def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,
296296
verbose : bool or integer
297297
Amount of verbosity
298298
299-
return_models : boolean, optional, default True
299+
return_models : boolean, optional, default False
300300
If ``True``, the function will return list of models. Setting it
301301
to ``False`` will change the function output returning the values
302302
of the alphas and the coefficients along the path. Returning the
@@ -628,7 +628,7 @@ def fit(self, X, y):
628628
precompute=precompute, Xy=this_Xy,
629629
fit_intercept=False, normalize=False, copy_X=True,
630630
verbose=False, tol=self.tol, positive=self.positive,
631-
return_models=False, X_mean=X_mean, X_std=X_std,
631+
X_mean=X_mean, X_std=X_std,
632632
coef_init=coef_[k], max_iter=self.max_iter)
633633
coef_[k] = this_coef[:, 0]
634634
dual_gaps_[k] = this_dual_gap[0]
@@ -827,7 +827,6 @@ def _path_residuals(X, y, train, test, path, path_params, l1_ratio=1,
827827

828828
# del path_params['precompute']
829829
path_params = path_params.copy()
830-
path_params['return_models'] = False
831830
path_params['fit_intercept'] = False
832831
path_params['normalize'] = False
833832
path_params['Xy'] = Xy

sklearn/linear_model/tests/test_coordinate_descent.py

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def test_lasso_path_return_models_vs_new_return_gives_same_coefficients():
189189
with warnings.catch_warnings():
190190
warnings.simplefilter("ignore", DeprecationWarning)
191191
coef_path = [e.coef_ for e in lasso_path(X, y, alphas=alphas,
192+
return_models=True,
192193
fit_intercept=False)]
193194

194195
# Use lars_path and lasso_path(new output) with 1D linear interpolation

sklearn/linear_model/tests/test_least_angle.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,17 @@ def test_lasso_lars_vs_lasso_cd_ill_conditioned():
331331

332332
_, lasso_coef2, _ = linear_model.lasso_path(X, y,
333333
alphas=lars_alphas, tol=1e-6,
334-
return_models=False,
335334
fit_intercept=False)
336335

337336
lasso_coef = np.zeros((w.shape[0], len(lars_alphas)))
338-
for i, model in enumerate(linear_model.lasso_path(X, y,
339-
alphas=lars_alphas,
340-
tol=1e-6,
341-
fit_intercept=False)):
342-
lasso_coef[:, i] = model.coef_
337+
with warnings.catch_warnings():
338+
warnings.simplefilter("ignore", DeprecationWarning)
339+
for i, model in enumerate(linear_model.lasso_path(X, y,
340+
alphas=lars_alphas,
341+
tol=1e-6,
342+
return_models=True,
343+
fit_intercept=False)):
344+
lasso_coef[:, i] = model.coef_
343345

344346
np.testing.assert_array_almost_equal(lars_coef, lasso_coef, decimal=1)
345347
np.testing.assert_array_almost_equal(lars_coef, lasso_coef2, decimal=1)

0 commit comments

Comments
 (0)