library(tidyr)
library(dplyr)
library(ggplot2)
data(ames, package = "modeldata")
spline_rec <- recipe(Sale_Price ~ Longitude, data = ames) |>
step_spline_natural(Longitude, deg_free = 6, keep_original_cols = TRUE) |>
prep()
tidy(spline_rec, number = 1)
# Show where each feature is active
spline_rec |>
bake(new_data = NULL,-Sale_Price) |>
pivot_longer(c(starts_with("Longitude_")), names_to = "feature", values_to = "value") |>
mutate(feature = gsub("Longitude_", "feature ", feature)) |>
filter(value > 0) |>
ggplot(aes(x = Longitude, y = value)) +
geom_line() +
facet_wrap(~ feature)
Run the code above in your browser using DataLab