LASSO Regression
Least Absolute Shrinkage and Selection Operator (LASSO) follows a similar structure to that of ridge regression, except for the penalty term, which in LASSO regression is L1 (sum of absolute values of the coefficient estimates) in contrast to ridge regression where it's L2 (sum of squared coefficients):
LASSO regression turns some coefficients to zero, thus the effect of a particular variable is nullified. This makes it efficient in feature selection while fitting data.
Exercise 57: LASSO Regression
In this exercise, we will apply LASSO regression on the Beijing PM2.5 dataset. We will use the same cv.glmnet() function to find the optimal lambda value.
Perform the following steps to complete the exercise:
First, let's set up seed to get similar results using the following command:
set.seed(100) #Setting the seed to get similar results. model_LASSO = cv.glmnet(X,Y,alpha = 1,lambda = 10^seq(4,-1,-0.1))
Now, use the following command to find the optimal value of lambda after cross...