2
$\begingroup$

I have a regression problem where I need all coefficents to be positive and the intercept to be zero. I can do this in sklearn but i don't understand how the algoritm can force this conditions through the loss function. Any references will be appreciated.

\begin{align}\hat{\beta}^\text{lasso}&=\underset{\beta}{ \arg\min}\sum_{i=1}^N \left(y_i-\beta_0-\sum_{j=1}^Px_{ij}\beta_j\right)^2\\&\textrm{subject to}\sum_{j=1}^P|\beta_j|\leq t. \end{align}

$\endgroup$
2
  • 7
    $\begingroup$ Lasso does not constrain parameters to be positive. $\endgroup$
    – Tim
    Commented Jan 6, 2020 at 15:17
  • $\begingroup$ But in sklearn there is a positive argument that allows you to do so. $\endgroup$ Commented Oct 3, 2022 at 1:14

2 Answers 2

1
$\begingroup$

Lasso does neither of those things. It forces the coefficients of the least important predictors to be zero, but not necessarily the intercept (this would be problem dependent). At the same time, since the loss function contains the absolute value of the coefficients, their sign is irrelevant and only their magnitude has an effect on the result.

$\endgroup$
1
$\begingroup$

Forcing the intercept to be zero is straightforward: leave it out. Don’t estimate an intercept or let it enter the regression equation whatsoever. Estimate $\mathbb E\left[Y\vert X\right]=\beta_1X_1+\dots+\beta_pX_p$, rather than $=\beta_0+\beta_1X_1+\dots+\beta_pX_p$.

Regarding the Python function argument allowing for the coefficients all to be positive, I suspect that this is just another constraint on the optimization. You minimize square loss subject to the $L_1$ norm of the parameter vector being smaller than some value and subject to all components of the parameter vector being non-negative.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.