# \donttest{
library(recipes)
library(rsample)
library(parsnip)
set.seed(6735)
tr_te_split <- initial_split(mtcars)
spline_rec <- recipe(mpg ~ ., data = mtcars) %>%
step_ns(disp)
lin_mod <- linear_reg() %>%
set_engine("lm")
spline_res <- last_fit(lin_mod, spline_rec, split = tr_te_split)
spline_res
# test set results
spline_res$.metrics[[1]]
# or use a workflow
library(workflows)
spline_wfl <-
workflow() %>%
add_recipe(spline_rec) %>%
add_model(lin_mod)
last_fit(spline_wfl, split = tr_te_split)
# }
Run the code above in your browser using DataLab