bag_instance_sampling: Sample 'mild_df' object by bags and instances

View source: R/utils.R

bag_instance_samplingR Documentation

Sample mild_df object by bags and instances

Description

From a mild_df object, return a sample that evenly pulls from the unique bags and unique instances from each bag as much as possible. This is a form of stratified sampling to avoid randomly sampling many rows from a few bags.

Usage

bag_instance_sampling(data, size)

Arguments

data

A mild_df object containing the data.

size

A non-negative integer giving the number of rows to choose from data.

Value

A numeric vector of length size indicating which rows were sampled.

Author(s)

Sean Kent

Examples

mil_data <- generate_mild_df(positive_dist = "mvnormal",
                             nbag = 2,
                             ninst = 2,
                             nsample = 2)

rows <- bag_instance_sampling(mil_data, 6)
table(mil_data$bag_name[rows])
table(mil_data$instance_name[rows])

rows <- bag_instance_sampling(mil_data, 4)
table(mil_data$bag_name[rows])
table(mil_data$instance_name[rows])


mildsvm documentation built on July 14, 2022, 9:08 a.m.