JuliaStats / Lasso.jl

Lasso/Elastic Net linear and generalized linear models
Other
143 stars 31 forks source link

Package fails when response is zero vector. #51

Open barankarakus opened 3 years ago

barankarakus commented 3 years ago

Running the following

` using Lasso

X = [1 2; 3 4] y = zeros(2) fit(LassoPath, X, y) `

leads to the error message

ERROR: coordinate descent failed to converge in 10000 iterations at λ = NaN

Having done some debugging, the problem is the following: when computing the λ values that make up the path, λmax is computed to be 0, resulting in λ being a vector of NaNs. The correct thing to output is that the null model is the only Lasso solution.

The easiest way to fix this is to have a check for λ being a vector of all NaNs right after line 490 in Lasso.jl. This is not a good solution, though, since we're relying on the fact that λmax = 0 implies λ is a vector of all NaNs; λ may be a vector of all NaNs due to another reason.

I think the best solution will be to modify build_model so that, in addition to the 4 values it currently returns, it also returns λmax. Then, we can have a check for λmax == 0 in line 491.