Skip to content

Commit ad47b19

Browse files
add fit_intercept docstring, factorized duplicate code
1 parent c38c00d commit ad47b19

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

skglm/experimental/sqrt_lasso.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ class SqrtLasso(LinearModel, RegressorMixin):
102102
verbose : bool, default False
103103
Amount of verbosity. 0/False is silent.
104104
105-
fit_intercept: bool, default True
106-
xxx
105+
fit_intercept: bool, optional (default=True)
106+
Whether or not to fit an intercept.
107107
"""
108108

109109
def __init__(self, alpha=1., max_iter=100, max_pn_iter=100, p0=10,
@@ -204,14 +204,10 @@ def path(self, X, y, alphas=None, eps=1e-3, n_alphas=10):
204204
+ self.fit_intercept)
205205

206206
try:
207-
if self.fit_intercept:
208-
coef, _, _ = self.solver_.solve(
209-
X, y, sqrt_quadratic, l1_penalty,
210-
w_init=coef_init, Xw_init=X @ coef_init[:-1] + coef_init[-1])
211-
else:
212-
coef, _, _ = self.solver_.solve(
213-
X, y, sqrt_quadratic, l1_penalty,
214-
w_init=coef_init, Xw_init=X @ coef_init)
207+
coef, _, _ = self.solver_.solve(
208+
X, y, sqrt_quadratic, l1_penalty,
209+
w_init=coef_init, Xw_init=X @ coef_init[:-1] + coef_init[-1]
210+
if self.fit_intercept else X @ coef_init)
215211
coefs[i] = coef
216212
except ValueError as val_exception:
217213
# make sure to catch residual error

0 commit comments

Comments
 (0)