我想在同一个数据集上评估几个(主要是)线性回归模型的性能。我想也许使用tidymodels
包和workflowsets::workflow_set()
可能的工作。我遵循了此处的示例,但我无法弄清楚如何从代码中实际获得合适的结果。
# Load packages
library("tidyverse")
library('workflowsets')
library("parsnip")
library("recipes")
# Data
dat <-
structure(list(q = c(66.65, 75.58, 83.06, 91.28, 119.26, 133.14,
146.32, 153.39, 168.57, 182.36, 210.09, 188.19, 213.42, 296.95,
326.33, 358.63, 475.99, 475.99, 683.44, 683.44, 838.49, 1282.1,
1648.97, 1572.97, 2055.14, 2521.39, 2685.11, 2859.46, 3242.87,
6899.19, 6377.42, 7581.96, 9599.32), c = c(317.06, 283.99, 279.56,
283.99, 227.84, 227.84, 262.5, 242.64, 270.9, 266.67, 210.6,
235.12, 235.12, 210.6, 207.31, 227.84, 220.78, 194.67, 177.13,
207.31, 179.94, 177.13, 182.79, 139.89, 148.98, 144.36, 137.71,
158.66, 142.11, 142.11, 119.52, 110.48, 158.66), c_less_c_nought = c(300.06,
266.99, 262.56, 266.99, 210.84, 210.84, 245.5, 225.64, 253.9,
249.67, 193.6, 218.12, 218.12, 193.6, 190.31, 210.84, 203.78,
177.67, 160.13, 190.31, 162.94, 160.13, 165.79, 122.89, 131.98,
127.36, 120.71, 141.66, 125.11, 125.11, 102.52, 93.48, 141.66
)), row.names = c(NA, -33L), class = c("tbl_df", "tbl", "data.frame"
))
# Recipes for models
eq1_mod1_recipe <-
recipes::recipe(c ~ q, data = dat) %>%
step_log(c, q, base = 10)
eq2_mod2_a_recipe <-
recipes::recipe(c_less_c_nought ~ q, data = dat) %>%
step_log(c_less_c_nought, q, base = 10)
# Define model types
lm_model <-
parsnip::linear_reg() %>%
parsnip::set_engine("lm") %>%
parsnip::set_mode("regression")
# Run the models?
cq_models <-
workflowsets::workflow_set(
preproc = list(eq1m1 = eq1_mod1_recipe, e2m2a = eq2_mod2_a_recipe),
models = list(lm = lm_model)
)
看来这实际上并不适合模型本身。我需要什么/在哪里添加代码以适应线性模型?
或者,是否有更好但仍然“整洁”的方式来做到这一点?接受建议。