data(ames, package = "modeldata")
set.seed(123)
group_vfold_cv(ames, group = Neighborhood, v = 5)
group_vfold_cv(
ames,
group = Neighborhood,
v = 5,
balance = "observations"
)
group_vfold_cv(ames, group = Neighborhood, v = 5, repeats = 2)
# Leave-one-group-out CV
group_vfold_cv(ames, group = Neighborhood)
library(dplyr)
data(Sacramento, package = "modeldata")
city_strata <- Sacramento %>%
group_by(city) %>%
summarize(strata = mean(price)) %>%
summarize(city = city,
strata = cut(strata, quantile(strata), include.lowest = TRUE))
sacramento_data <- Sacramento %>%
full_join(city_strata, by = "city")
group_vfold_cv(sacramento_data, city, strata = strata)
Run the code above in your browser using DataLab