crossv_lpo: Generate cross-validated leave-p-out test/training pairs

Description Usage Arguments Value Methods (by class) References Examples

Description

Generate cross-validated leave-one-out or leave-p-out test/training pairs. The function leave-p-out generates leave-p-out test/training pairs, while the function leave-one-out convenience function for the common case of leave-one-out cross-validation, p = 1.

Usage

1
2
3
4
5
6
7
8
9
crossv_lpo(data, p, ...)

## S3 method for class 'data.frame'
crossv_lpo(data, p = 1L, ...)

## S3 method for class 'grouped_df'
crossv_lpo(data, p = 1L, ...)

crossv_loo(data)

Arguments

data

A data frame or vector

p

The number of elements to include in the test set.

...

Passed to methods

Value

A data frame with n choose p rows and the following columns:

train

A list of resample objects. Training sets.

test

A list of resample objects. Test sets.

.id

An integer vector of identifiers

Methods (by class)

References

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Example originally from modelr::crossv_mc
library("purrr")
library("dplyr")

# LOO cross-validation
cv1 <- crossv_loo(mtcars)
models <- map(cv1$train, ~ lm(mpg ~ wt, data = .))
summary(map2_dbl(models, cv1$test, modelr::rmse))

# Leave-p-Out cross-validation with p = 2
cv2 <- crossv_lpo(mtcars, p = 2)
models <- map(cv2$train, ~ lm(mpg ~ wt, data = .))
summary(map2_dbl(models, cv2$test, modelr::rmse))

jrnold/resamplr documentation built on May 20, 2019, 1:05 a.m.