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.
rsetObjects Contain Many Resamples
The 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.
modelr, the resamples are stored in data-frame-like
tibble object. As a simple example, here is a small set of bootstraps of the
library(rsample) set.seed(8584) bt_resamples <- bootstraps(mtcars, times = 3) bt_resamples
The resamples are stored in the
splits column in an object that has class
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
first_resample <- bt_resamples$splits[] first_resample
This indicates that there were
r dim(bt_resamples$splits[])["analysis"] data points in the analysis set,
r dim(bt_resamples$splits[])["assessment"] instances were in the assessment set, and that the original data contained
r dim(bt_resamples$splits[])["n"] data points. These results can also be determined using the
dim function on an
To obtain either of these data sets from an
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
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.