knitr::opts_chunk$set( message = FALSE, digits = 3, collapse = TRUE, comment = "#>" ) options(digits = 3)
We define a resample as the result of a two-way split of a data set. For example, when bootstrapping, one part of the resample is a sample with replacement of the original data. The other part of the split contains the instances that were not contained in the bootstrap sample. Cross-validation is another type of resampling.
rset
Objects Contain Many ResamplesThe main class in the package (rset
) is for a set or collection of resamples. In 10-fold cross-validation, the set would consist of the 10 different resamples of the original data.
Like modelr, the resamples are stored in data-frame-like tibble
object. As a simple example, here is a small set of bootstraps of the mtcars
data:
library(rsample) set.seed(8584) bt_resamples <- bootstraps(mtcars, times = 3) bt_resamples
rsplit
ObjectsThe resamples are stored in the splits
column in an object that has class rsplit
.
In this package we use the following terminology for the two partitions that comprise a resample:
(Aside: While some might use the term "training" and "testing" for these data sets, we avoid them since those labels often conflict with the data that result from an initial partition of the data that is typically done before resampling. The training/test split can be conducted using the initial_split()
function in this package.)
Let's look at one of the rsplit
objects
first_resample <- bt_resamples$splits[[1]] first_resample
This indicates that there were r dim(bt_resamples$splits[[1]])["analysis"]
data points in the analysis set, r dim(bt_resamples$splits[[1]])["assessment"]
instances were in the assessment set, and that the original data contained r dim(bt_resamples$splits[[1]])["n"]
data points. These results can also be determined using the dim
function on an rsplit
object.
To obtain either of these data sets from an rsplit
, the as.data.frame()
function can be used. By default, the analysis set is returned but the data
option can be used to return the assessment data:
head(as.data.frame(first_resample)) as.data.frame(first_resample, data = "assessment")
Alternatively, you can use the shortcuts analysis(first_resample)
and assessment(first_resample)
.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.