March 2019
Beginner to intermediate
448 pages
13h 14m
English
In this example, we will follow the same logic, but we will use alpha=1, forcing glmnet to do Lasso. This will penalize the coefficients now using the L1 norm, which means that some of the coefficients (the irrelevant ones) will be pushed towards zero exactly. Therefore, some data scientists use LASSO as a variable selection tool:
library(MASS) library(tidyr) library(ggplot2) library(glmnet) get_results <- function(lambda){ coeffs_total = data.frame(V1=numeric(), V2=numeric(), V3=numeric(), V4=numeric(), V5=numeric()) for (q in 1:100){ V1 = runif(1000)*100 V2 = runif(1000)*10 + V1 V3 = runif(1000)*100 V4 = runif(1000)*10 + V3 V5 = runif(1000)*100 Residuals = runif(1000)*100 ...
Read now
Unlock full access