Self-implemented Lasso algorithm
This file contains a lasso implementation in R, using coordinate descent algorithm, based on the essay by Tibshirani.
- The png files:
coordinate iteration formula.pngandLasso- essay by Tibshirani(Part),pngdescribe the basis of my code Sor soft thresholding function.Ris the code for soft thresholding function(see incoordinate iteration formula.png)update function.Ris the code for coordinate wise update functionIteration Function.Rfor one iteration stepcoordinate descent.Ris the final code
Here's a problem. When I test my code on the R-built-in data set mtcars, it works well for other coefficients(supress some to zero and pick the most significant ones) except for one variable (hp in the data set), compared with the official package glmnet; and I can't figure out why.
Besides, I test my code in some self-create data, like, x1,x2,x3 are independent variables,