我正在使用glmnet引擎在潮汐模型中执行弹性净线性回归。
如果我直接在glmnet中运行这个,我可以做这样的事情:
cv_fit <- cv.glmnet(
y = response_vec,
x = predictor_matrix,
nfolds = 10,
alpha = 0.95,
type.measure = "mse",
keep = TRUE)
然后我可以得到这样的拟合值:
fitted_y <- cv_fit$fit.preval
然而,我找不到如何获得使用parsnip拟合的glmnet模型的拟合值/残差。感谢您的帮助。
我要找的是control
参数。save_pred = TRUE
确保拟合值存储在返回的对象中:
tuning_mod <- wf %>%
tune::tune_grid(
resample = rsample::vfold_cv(data = my_data, v = 10, repeats = 3),
grid = dials::grid_regular(x = dials::penalty(), levels = 200),
metrics = yardstick::metric_set(yardstick::rmse, yardstick::rsq),
control = control_resamples(save_pred = TRUE)
)
tune::collect_predictions(tuning_mod)