# Lasso fit with non-negative coefficients

**URL:** https://discourse.julialang.org/t/lasso-fit-with-non-negative-coefficients/79923
**Category:** Modelling & Simulations
**Tags:** regression
**Created:** [April 24, 2022, 1:05am UTC](https://discourse.julialang.org/t/lasso-fit-with-non-negative-coefficients/79923 "2022-04-24T01:05:19Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Aminath\_Shausan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminath_shausan/32/33587_2.png) [@Aminath\_Shausan](https://discourse.julialang.org/u/Aminath_Shausan)
#### Post date: [April 24, 2022, 1:05am UTC](https://discourse.julialang.org/t/lasso-fit-with-non-negative-coefficients/79923/1 "2022-04-24T01:05:19Z")

</div>

Hi  
I am using a Lasso model for feature selection. At present I use the function

```julia
lassoFit = fit(LassoPath, X_train, Y_train, λ = lamGrid, maxncoef=maxncoef)

```

I have the following question.

(1) Some estimated coefficients are negative for each _lamGrid_ value, which don’t give a reasonable biological meaning to my problem. I need all coefficients to be non-negative. Is there a way to restrict the coefficients to be non-negative?

Thanks

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [April 24, 2022, 5:15am UTC](https://discourse.julialang.org/t/lasso-fit-with-non-negative-coefficients/79923/2 "2022-04-24T05:15:43Z")

</div>

You may need to mention which package you’re talking about.

---

<div class="post-metadata">

### Author: ![Aminath\_Shausan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminath_shausan/32/33587_2.png) [@Aminath\_Shausan](https://discourse.julialang.org/u/Aminath_Shausan)
#### Post date: [April 24, 2022, 9:27pm UTC](https://discourse.julialang.org/t/lasso-fit-with-non-negative-coefficients/79923/3 "2022-04-24T21:27:56Z")

</div>

@baggepinnen , I use the `lasso` package [Lasso paths · Lasso.jl](https://juliastats.org/Lasso.jl/stable/lasso/).  
Also, how is the out put `pct_dev` computed in the package?  
Thanks

---

<div class="post-metadata">

### Author: ![biona001](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/biona001/32/16497_2.png) [@biona001](https://discourse.julialang.org/u/biona001)
#### Post date: [April 25, 2022, 1:30am UTC](https://discourse.julialang.org/t/lasso-fit-with-non-negative-coefficients/79923/4 "2022-04-25T01:30:29Z")

</div>

It seems like [GLMNet.jl](https://github.com/JuliaStats/GLMNet.jl) supports the `constraints` keyword that you can use.

---

<div class="post-metadata">

### Author: ![Aminath\_Shausan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminath_shausan/32/33587_2.png) [@Aminath\_Shausan](https://discourse.julialang.org/u/Aminath_Shausan)
#### Post date: [April 26, 2022, 1:40am UTC](https://discourse.julialang.org/t/lasso-fit-with-non-negative-coefficients/79923/5 "2022-04-26T01:40:49Z")

</div>

@biona001 Thanks for the suggestion. It worked with the GLMNet.jl
