# rsample ## Overview The rsample package provides functions to create different types of resamples and corresponding classes for their analysis. The goal is to have a modular set of methods that can be used for: - resampling for estimating the sampling distribution of a statistic - estimating model performance using a holdout set The scope of rsample is to provide the basic building blocks for creating and analyzing resamples of a data set, but this package does not include code for modeling or calculating statistics. The [Working with Resample Sets](https://rsample.tidymodels.org/articles/Working_with_rsets.html) vignette gives a demonstration of how rsample tools can be used when building models. Note that resampled data sets created by rsample are directly accessible in a resampling object but do not contain much overhead in memory. Since the original data is not modified, R does not make an automatic copy. For example, creating 50 bootstraps of a data set does not create an object that is 50-fold larger in memory: ``` r library(rsample) library(mlbench) data(LetterRecognition) lobstr::obj_size(LetterRecognition) #> 2,644,640 B set.seed(35222) boots <- bootstraps(LetterRecognition, times = 50) lobstr::obj_size(boots) #> 6,686,776 B # Object size per resample lobstr::obj_size(boots)/nrow(boots) #> 133,735.5 B # Fold increase is <<< 50 as.numeric(lobstr::obj_size(boots)/lobstr::obj_size(LetterRecognition)) #> [1] 2.528426 ``` ^(Created on 2022-02-28 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)) The memory usage for 50 bootstrap samples is less than 3-fold more than the original data set. ## Installation To install it, use: ``` r install.packages("rsample") ``` And the development version from [GitHub](https://github.com/) with: ``` r # install.packages("pak") pak::pak("rsample") ``` ## Contributing This project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. - For questions and discussions about tidymodels packages, modeling, and machine learning, please [post on Posit Community](https://forum.posit.co/new-topic?category_id=15&tags=tidymodels,question). - If you think you have encountered a bug, please [submit an issue](https://github.com/tidymodels/rsample/issues). - Either way, learn how to create and share a [reprex](https://reprex.tidyverse.org/articles/articles/learn-reprex.html) (a minimal, reproducible example), to clearly communicate about your code. - Check out further details on [contributing guidelines for tidymodels packages](https://www.tidymodels.org/contribute/) and [how to get help](https://www.tidymodels.org/help/). # Package index ## Resampling methods - [`initial_split()`](https://rsample.tidymodels.org/reference/initial_split.md) [`initial_time_split()`](https://rsample.tidymodels.org/reference/initial_split.md) [`training()`](https://rsample.tidymodels.org/reference/initial_split.md) [`testing()`](https://rsample.tidymodels.org/reference/initial_split.md) [`group_initial_split()`](https://rsample.tidymodels.org/reference/initial_split.md) : Simple Training/Test Set Splitting - [`initial_validation_split()`](https://rsample.tidymodels.org/reference/initial_validation_split.md) [`initial_validation_time_split()`](https://rsample.tidymodels.org/reference/initial_validation_split.md) [`group_initial_validation_split()`](https://rsample.tidymodels.org/reference/initial_validation_split.md) [`training(`*``*`)`](https://rsample.tidymodels.org/reference/initial_validation_split.md) [`testing(`*``*`)`](https://rsample.tidymodels.org/reference/initial_validation_split.md) [`validation()`](https://rsample.tidymodels.org/reference/initial_validation_split.md) : Create an Initial Train/Validation/Test Split - [`validation_set()`](https://rsample.tidymodels.org/reference/validation_set.md) [`analysis(`*``*`)`](https://rsample.tidymodels.org/reference/validation_set.md) [`assessment(`*``*`)`](https://rsample.tidymodels.org/reference/validation_set.md) [`training(`*``*`)`](https://rsample.tidymodels.org/reference/validation_set.md) [`validation(`*``*`)`](https://rsample.tidymodels.org/reference/validation_set.md) [`testing(`*``*`)`](https://rsample.tidymodels.org/reference/validation_set.md) : Create a Validation Split for Tuning - [`bootstraps()`](https://rsample.tidymodels.org/reference/bootstraps.md) : Bootstrap Sampling - [`group_bootstraps()`](https://rsample.tidymodels.org/reference/group_bootstraps.md) : Group Bootstraps - [`vfold_cv()`](https://rsample.tidymodels.org/reference/vfold_cv.md) : V-Fold Cross-Validation - [`group_vfold_cv()`](https://rsample.tidymodels.org/reference/group_vfold_cv.md) : Group V-Fold Cross-Validation - [`mc_cv()`](https://rsample.tidymodels.org/reference/mc_cv.md) : Monte Carlo Cross-Validation - [`group_mc_cv()`](https://rsample.tidymodels.org/reference/group_mc_cv.md) : Group Monte Carlo Cross-Validation - [`clustering_cv()`](https://rsample.tidymodels.org/reference/clustering_cv.md) : Cluster Cross-Validation - [`nested_cv()`](https://rsample.tidymodels.org/reference/nested_cv.md) : Nested or Double Resampling - [`loo_cv()`](https://rsample.tidymodels.org/reference/loo_cv.md) : Leave-One-Out Cross-Validation - [`rolling_origin()`](https://rsample.tidymodels.org/reference/rolling_origin.md) **\[superseded\]** : Rolling Origin Forecast Resampling - [`sliding_window()`](https://rsample.tidymodels.org/reference/slide-resampling.md) [`sliding_index()`](https://rsample.tidymodels.org/reference/slide-resampling.md) [`sliding_period()`](https://rsample.tidymodels.org/reference/slide-resampling.md) : Time-based Resampling - [`apparent()`](https://rsample.tidymodels.org/reference/apparent.md) : Sampling for the Apparent Error Rate - [`permutations()`](https://rsample.tidymodels.org/reference/permutations.md) : Permutation sampling - [`manual_rset()`](https://rsample.tidymodels.org/reference/manual_rset.md) : Manual resampling ## Analysis - [`int_pctl()`](https://rsample.tidymodels.org/reference/int_pctl.md) [`int_t()`](https://rsample.tidymodels.org/reference/int_pctl.md) [`int_bca()`](https://rsample.tidymodels.org/reference/int_pctl.md) : Bootstrap confidence intervals - [`reg_intervals()`](https://rsample.tidymodels.org/reference/reg_intervals.md) : A convenience function for confidence intervals with linear-ish parametric models ## Utilities - [`.get_fingerprint()`](https://rsample.tidymodels.org/reference/get_fingerprint.md) : Obtain a identifier for the resamples - [`as.data.frame(`*``*`)`](https://rsample.tidymodels.org/reference/as.data.frame.rsplit.md) [`analysis()`](https://rsample.tidymodels.org/reference/as.data.frame.rsplit.md) [`assessment()`](https://rsample.tidymodels.org/reference/as.data.frame.rsplit.md) : Convert an `rsplit` object to a data frame - [`add_resample_id()`](https://rsample.tidymodels.org/reference/add_resample_id.md) : Augment a data set with resampling identifiers - [`complement()`](https://rsample.tidymodels.org/reference/complement.md) : Determine the Assessment Samples - [`form_pred()`](https://rsample.tidymodels.org/reference/form_pred.md) : Extract Predictor Names from Formula or Terms - [`get_rsplit()`](https://rsample.tidymodels.org/reference/get_rsplit.md) : Retrieve individual rsplits objects from an rset - [`labels(`*``*`)`](https://rsample.tidymodels.org/reference/labels.rset.md) [`labels(`*``*`)`](https://rsample.tidymodels.org/reference/labels.rset.md) : Find Labels from rset Object - [`labels(`*``*`)`](https://rsample.tidymodels.org/reference/labels.rsplit.md) : Find Labels from rsplit Object - [`make_splits()`](https://rsample.tidymodels.org/reference/make_splits.md) : Constructors for split objects - [`make_strata()`](https://rsample.tidymodels.org/reference/make_strata.md) : Create or Modify Stratification Variables - [`populate()`](https://rsample.tidymodels.org/reference/populate.md) : Add Assessment Indices - [`reshuffle_rset()`](https://rsample.tidymodels.org/reference/reshuffle_rset.md) : "Reshuffle" an rset to re-generate a new rset with the same parameters - [`reverse_splits()`](https://rsample.tidymodels.org/reference/reverse_splits.md) : Reverse the analysis and assessment sets - [`rsample2caret()`](https://rsample.tidymodels.org/reference/rsample2caret.md) [`caret2rsample()`](https://rsample.tidymodels.org/reference/rsample2caret.md) : Convert Resampling Objects to Other Formats - [`rset_reconstruct()`](https://rsample.tidymodels.org/reference/rset_reconstruct.md) : Extending rsample with new rset subclasses - [`tidy(`*``*`)`](https://rsample.tidymodels.org/reference/tidy.rsplit.md) [`tidy(`*``*`)`](https://rsample.tidymodels.org/reference/tidy.rsplit.md) [`tidy(`*``*`)`](https://rsample.tidymodels.org/reference/tidy.rsplit.md) [`tidy(`*``*`)`](https://rsample.tidymodels.org/reference/tidy.rsplit.md) : Tidy Resampling Object ## Compatibility - [`rsample-dplyr`](https://rsample.tidymodels.org/reference/rsample-dplyr.md) : Compatibility with dplyr # Articles ### All vignettes - [Common Resampling Patterns](https://rsample.tidymodels.org/articles/Common_Patterns.md): - [Bootstrap confidence intervals](https://rsample.tidymodels.org/articles/Applications/Intervals.md): - [Recipes with rsample](https://rsample.tidymodels.org/articles/Applications/Recipes_and_rsample.md): - [Introduction to rsample](https://rsample.tidymodels.org/articles/rsample.md): - [Working with resampling sets](https://rsample.tidymodels.org/articles/Working_with_rsets.md):