if (FALSE) { # rlang::is_installed("glmnet")
library(dplyr)
library(tidyr)
library(parsnip)
library(glmnet)
data <- filter(example_nested_data, id %in% 16:20)
nested_data <- nest(data, data = -id2)
model <- linear_reg(penalty = 1) %>%
set_engine("glmnet") %>%
nested()
fitted <- fit(model, z ~ x + y + a + b, nested_data)
multi_predict(fitted, example_nested_data,
penalty = c(0.1, 0.2, 0.3)
)
}
Run the code above in your browser using DataLab