Skip to content

Commit e4c49c5

Browse files
committed
RFC: Less diffs
1 parent 70a4077 commit e4c49c5

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

sklearn/linear_model/coordinate_descent.py

+17-24
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,21 @@ def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,
502502
return alphas, coefs, dual_gaps
503503

504504

505+
class _LassoStaticMixin:
506+
"""Mixin to add lasso_path as a staticmethod named path"""
507+
508+
@staticmethod
509+
def path(X, y, eps=1e-3, n_alphas=100, alphas=None,
510+
precompute='auto', Xy=None, copy_X=True, coef_init=None,
511+
verbose=False, return_n_iter=False, positive=False, **params):
512+
return lasso_path(X, y, eps, n_alphas, alphas,
513+
precompute, Xy, copy_X, coef_init,
514+
verbose, return_n_iter, positive, **params)
515+
516+
517+
_LassoStaticMixin.path.__doc__ = lasso_path.__doc__
518+
519+
505520
###############################################################################
506521
# ElasticNet model
507522

@@ -1242,7 +1257,7 @@ def fit(self, X, y):
12421257
return self
12431258

12441259

1245-
class LassoCV(LinearModelCV, RegressorMixin):
1260+
class LassoCV(LinearModelCV, RegressorMixin, _LassoStaticMixin):
12461261
"""Lasso linear model with iterative fitting along a regularization path.
12471262
12481263
See glossary entry for :term:`cross-validation estimator`.
@@ -1406,17 +1421,6 @@ def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True,
14061421
cv=cv, verbose=verbose, n_jobs=n_jobs, positive=positive,
14071422
random_state=random_state, selection=selection)
14081423

1409-
@staticmethod
1410-
def path(X, y, eps=1e-3, n_alphas=100, alphas=None,
1411-
precompute='auto', Xy=None, copy_X=True, coef_init=None,
1412-
verbose=False, return_n_iter=False, positive=False, **params):
1413-
return lasso_path(
1414-
X, y, eps, n_alphas, alphas, precompute, Xy, copy_X, coef_init,
1415-
verbose, return_n_iter, positive, **params)
1416-
1417-
1418-
LassoCV.path.__doc__ = lasso_path.__doc__
1419-
14201424

14211425
class ElasticNetCV(LinearModelCV, RegressorMixin):
14221426
"""Elastic Net model with iterative fitting along a regularization path.
@@ -2140,7 +2144,7 @@ def __init__(self, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,
21402144
self.selection = selection
21412145

21422146

2143-
class MultiTaskLassoCV(LinearModelCV, RegressorMixin):
2147+
class MultiTaskLassoCV(LinearModelCV, RegressorMixin, _LassoStaticMixin):
21442148
"""Multi-task Lasso model trained with L1/L2 mixed-norm as regularizer.
21452149
21462150
See glossary entry for :term:`cross-validation estimator`.
@@ -2295,14 +2299,3 @@ def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True,
22952299
max_iter=max_iter, tol=tol, copy_X=copy_X,
22962300
cv=cv, verbose=verbose, n_jobs=n_jobs, random_state=random_state,
22972301
selection=selection)
2298-
2299-
@staticmethod
2300-
def path(X, y, eps=1e-3, n_alphas=100, alphas=None,
2301-
precompute='auto', Xy=None, copy_X=True, coef_init=None,
2302-
verbose=False, return_n_iter=False, positive=False, **params):
2303-
return lasso_path(
2304-
X, y, eps, n_alphas, alphas, precompute, Xy, copy_X, coef_init,
2305-
verbose, return_n_iter, positive, **params)
2306-
2307-
2308-
MultiTaskLassoCV.path.__doc__ = lasso_path.__doc__

0 commit comments

Comments
 (0)