Learn R Programming

rsample (version 1.0.0)

group_vfold_cv: Group V-Fold Cross-Validation

Description

Group V-fold cross-validation creates splits of the data based on some grouping variable (which may have more than a single row associated with it). The function can create as many splits as there are unique values of the grouping variable or it can create a smaller set of splits where more than one value is left out at a time. A common use of this kind of resampling is when you have repeated measures of the same subject.

Usage

group_vfold_cv(data, group = NULL, v = NULL, ...)

Value

A tibble with classes group_vfold_cv, rset, tbl_df, tbl, and data.frame. The results include a column for the data split objects and an identification variable.

Arguments

data

A data frame.

group

A variable in data (single character or name) used for grouping observations with the same value to either the analysis or assessment set within a fold.

v

The number of partitions of the data set. If left as NULL, v will be set to the number of unique values in the group.

...

Not currently used.

Examples

Run this code
data(Sacramento, package = "modeldata")

set.seed(123)
group_vfold_cv(Sacramento, group = city, v = 5)

Run the code above in your browser using DataLab