glmnet models

if (requireNamespace("glmnet", quietly = TRUE)) {
  library(tidypredict)
  library(glmnet)
  library(dplyr)
  eval_code <- TRUE
} else {
  eval_code <- FALSE
}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = eval_code
)

| Function |Works| |---------------------------------------------------------------|-----| |tidypredict_fit(), tidypredict_sql(), parse_model() | ✔ | |tidypredict_to_column() | ✔ | |tidypredict_test() | ✔ | |tidypredict_interval(), tidypredict_sql_interval() | ✗ | |parsnip | ✔ |

tidypredict_ functions

library(glmnet)

model <- glmnet::glmnet(mtcars[, -1], mtcars$mpg, lambda = 1)

mtcars %>% tidypredict_to_column(model) %>% glimpse() ```

parsnip

parsnip fitted models are also supported by tidypredict:

library(parsnip)

p_model <- linear_reg(penalty = 1) %>%
  set_engine("glmnet") %>%
  fit(mpg ~ ., data = mtcars)
tidypredict_fit(p_model)

Parse model spec

Here is an example of the model spec:

pm <- parse_model(model)
str(pm, 2)
str(pm$trees[1])


Try the tidypredict package in your browser

Any scripts or data that you put into this service are public.

tidypredict documentation built on Nov. 29, 2025, 9:06 a.m.