find.division.strat: Compute a stratified random partition of the input data

Description Usage Arguments Details Value See Also Examples

View source: R/find.division.strat.R

Description

Function to determine a random partition of the labeled input vector into a fixed number of folds, such that each fold has around the same proportion of two-class labels.

Usage

1
find.division.strat(labels, vett, n_fold)

Arguments

labels

binary -1/1 label vector. labels[i] is the label for the element vett[i].

vett

vector to be partitioned

n_fold

number of folds in which the argument vett must be partitioned

Details

The input vector "vett" is randomly partitioned into "n_fold" folds ensuring each fold contains roughly the same proportions of positives and negative labels, according to the labeling "labels"

Value

List with n_fold elements, the i-th element is a vector corresponding to i-th fold.

See Also

find.division.not.strat

Examples

1
2
3
4
5
6
7
8
n <- 100;
vett <- runif(n, 0, 1)
labels <- c(rep(1, floor(n/3)), rep(-1, ceiling(2*n/3)));
n_fold <- 5;
fold_list <- find.division.strat(labels, vett, n_fold);
length(fold_list);
## number of positives in the first fold
sum(labels(fold_list[[1]]) > 0);

COSNet documentation built on Nov. 8, 2020, 8:12 p.m.