I want to verify the code to specify a ridge model, a lasso model, and an elastic net model, using parsnip and glmnet and the penalty and mixture arguments.
I am confused because the documentation states:
-
mixture : The proportion of L1 regularization in the model.
and
-
mixture : A number between zero and one (inclusive) that represents the proportion of regularization that is used for the L2 penalty (i.e. weight decay, or ridge regression) versus L1 (the lasso) ( glmnet and spark only).
So I am not sure if the mixture represents the proportion of L1 or L2.
- Is this the correct specification for a ridge model?
linear_reg(penalty = .10, mixture = 0) %>% # mixture = 0 meaning no L1 penalty
set_mode("regression") %>%
set_engine("glmnet") %>%
fit(y ~ ., data = dta)
- Is this the correct specification for a lasso model?
linear_reg(penalty = .10, mixture = 1) %>% # mixture = 1 meaning no L2 penalty
set_mode("regression") %>%
set_engine("glmnet") %>%
fit(y ~ ., data = dta)
- Is this the correct specification for an elastic net model?
linear_reg(penalty = .10, mixture = .6) %>% # this is a mixture of both L1 and L2. Is it 60% L1 or 60% L2?
set_mode("regression") %>%
set_engine("glmnet") %>%
fit(y ~ ., data = dta)