I'm trying to create nested cross-validations using the rsample
package, and I use purrr::map2
to create them multiple times, with differing amount of folds as dictated by the v
parameter. However, the vfold_cv
function does not accept the v
parameter, and instead I get this error: Error: v must be a single integer.
In the reprex below, I'm simulating the situation using the mtcars
data, by creating a cross validation for each cylinder. Replacing .y
with a number works, but I need the parameter to vary with each cylinder by using the n
column.
library(purrr) library(parsnip) library(rsample) library(tidyr) data("mtcars") nested <- mtcars %>% select(cyl, disp:gear) %>% group_by(cyl) %>% nest(data = disp:gear) %>% cbind(n = 2:4) nested %>% group_by(cyl) %>% mutate(cv = map2(data, n, ~nested_cv(.x, inside = vfold_cv(v = 10, repeats = 3), outside = vfold_cv(v = .y))))
Error: `v` must be a single integer.