crossv_loo_grouped | R Documentation |
data.frame
Expands the capability of the crossv_loo
and
crossv_mc
functions such that groups in a grouped
data frame form the basis of folds to be "left out" of a model training set
for cross-validation.
crossv_loo_grouped(data, id = ".id")
crossv_mc_grouped(data, n, test = 0.25, id = ".id")
data |
A grouped data frame. |
id |
Name of variable that gives each training set a unique integer id. |
# Normal crossv_loo
cv_iris <- modelr::crossv_loo(iris)
# Note that the number of training paritions is equal to nrow(iris)
# Use the new function
cv_iris2 <- crossv_loo_grouped(group_by(iris, Species))
# Note that the number of training partitions is equal to n_groups(data)
library(agridat)
wheat <- vargas.wheat2.yield
# Normal crossv_mc
cv_wheat <- modelr::crossv_mc(data = wheat, n = 10, test = 0.25)
# Note that partitions are made across environments or genotypes
# Use the new function
cv_wheat2 <- crossv_mc_grouped(data = group_by(wheat, env), n = 15)
# Note that partitions are made according to the group
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.