undersample_tomek: Undersample a dataset by removing Tomek links.

View source: R/undersample.R

undersample_tomekR Documentation

Undersample a dataset by removing Tomek links.

Description

A Tomek link is a minority instance and majority instance that are each other's nearest neighbor. This function removes sufficient Tomek links that are an instance of cls to yield m instances of cls. If desired, samples are randomly discarded to yield m rows if insufficient Tomek links are in the data.

Usage

undersample_tomek(data, cls, cls_col, m, tomek = "minor", force_m = TRUE, ...)

Arguments

data

Dataset to be undersampled.

cls

Majority class to be undersampled.

cls_col

Column in data containing class memberships.

m

Desired number of samples in undersampled dataset.

tomek

Definition used to determine if a point is considered a minority in the Tomek link definition.

  • minor: Minor classes are all those with fewer than m instances.

  • diff: Minor classes are all those that aren't cls.

force_m

If TRUE, uses random undersampling to discard samples if insufficient Tomek links are present to yield m rows of data.

...

Additional arguments passed to dist().

Value

Undersampled dataframe containing only cls.

Examples

table(iris$Species)
undersamp <- undersample_tomek(iris, "setosa", "Species", 15, tomek = "diff", force_m = TRUE)
nrow(undersamp)
undersamp2 <- undersample_tomek(iris, "setosa", "Species", 15, tomek = "diff", force_m = FALSE)
nrow(undersamp2)

scutr documentation built on Nov. 18, 2023, 1:08 a.m.