View source: R/trans_sample_strat.R
| sample_stratified | R Documentation |
Train/test split and k‑fold partitioning that preserve the target class proportions (strata).
sample_stratified(attribute)
attribute |
attribute target to model building |
returns an object of class sample_stratified
#using stratified sampling
sample <- sample_stratified("Species")
tt <- train_test(sample, iris)
# distribution of train
table(tt$train$Species)
# preparing dataset into four folds
folds <- k_fold(sample, iris, 4)
# distribution of folds
tbl <- NULL
for (f in folds) {
tbl <- rbind(tbl, table(f$Species))
}
head(tbl)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.