This post presents a R code for a k-fold cross validation of Lasso in the case of a gaussian regression (continuous Y). This work easily can be done by using a mean squared error.
Cross Validation in Lasso : Gaussian Regression
We have implemented a R code for the K-fold cross validation of lasso model with the binomial response in the previous post below.
The main output of this post is the following lasso cross validation figure for the case of a continuous Y variable. (top : cv.glmnet(), bottom : our result).
In fact, we are familiar with MSE because the linear regression model uses this measure in the textbook level. Since it is easier than the case of binomial response. let’s turn to the R code for this modification directly.
Cross Validation of Lasso with continuous Y variable
In the following R code, we use a built-in example data (QuickStartExample) for simplicity. In particular, we set arguments family = “gaussian” and type.measure = “mse” for a continuous dependent variable.
Running the above R code results in the next two \(\lambda\)s of two approaches (cv.glmnet() and our implementation). Except for the treatment of a mean squared error, calculation of lambda.min and lambda.1se is the same as that of the case of binomial response. Two figures for cross validation are omitted because we have already seen them at the beginning of this blog.
In this post, we can easily implement R code for a lasso cross validation with continuous dependent variable by a small modification of the binomial response case. \(\blacksquare\)