8000 Add option to restrict LassoCV to positive-only coefficients · jwchennlp/scikit-learn@0b20feb · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b20feb

Browse files
bwignallagramfort
authored andcommitted
Add option to restrict LassoCV to positive-only coefficients
1 parent 7001128 commit 0b20feb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

sklearn/linear_model/coordinate_descent.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ class LinearModelCV(six.with_metaclass(ABCMeta, LinearModel)):
861861
@abstractmethod
862862
def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True,
863863
normalize=False, precompute='auto', max_iter=1000, tol=1e-4,
864-
copy_X=True, cv=None, verbose=False):
864+
copy_X=True, cv=None, verbose=False, positive=False):
865865
self.eps = eps
866866
self.n_alphas = n_alphas
867867
self.alphas = alphas
@@ -873,6 +873,7 @@ def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True,
873873
self.copy_X = copy_X
874874
self.cv = cv
875875
self.verbose = verbose
876+
self.positive = positive
876877

877878
def fit(self, X, y):
878879
"""Fit linear model with coordinate descent
@@ -1051,6 +1052,9 @@ class LassoCV(LinearModelCV, RegressorMixin):
10511052
verbose : bool or integer
10521053
amount of verbosity
10531054
1055+
positive : bool, optional
1056+
If positive, restrict regression coefficients to be positive
1057+
10541058
Attributes
10551059
----------
10561060
``alpha_`` : float
@@ -1101,12 +1105,12 @@ class LassoCV(LinearModelCV, RegressorMixin):
11011105

11021106
def __init__(self, eps=1e-3, n_alphas=100, alphas=None, fit_intercept=True,
11031107
normalize=False, precompute='auto', max_iter=1000, tol=1e-4,
1104-
copy_X=True, cv=None, verbose=False):
1108+
copy_X=True, cv=None, verbose=False, positive=False):
11051109
super(LassoCV, self).__init__(
11061110
eps=eps, n_alphas=n_alphas, alphas=alphas,
11071111
fit_intercept=fit_intercept, normalize=normalize,
11081112
precompute=precompute, max_iter=max_iter, tol=tol, copy_X=copy_X,
1109-
cv=cv, verbose=verbose)
1113+
cv=cv, verbose=verbose, positive=positive)
11101114

11111115

11121116
class ElasticNetCV(LinearModelCV, RegressorMixin):

0 commit comments

Comments
 (0)
0