Learn R Programming

rtemis (version 1.4.3)

class_imbalance: Class Imbalance

Description

Calculate class imbalance as given by: $$I = K\cdot\sum_{i=1}^K (n_i/N - 1/K)^2$$ where \(K\) is the number of classes, and \(n_i\) is the number of instances of class \(i\)

Usage

class_imbalance(x)

Value

Numeric.

Arguments

x

Vector, factor: Outcome.

Author

EDG

Examples

Run this code
# iris is perfectly balanced
class_imbalance(iris[["Species"]])
# Simulate imbalanced outcome
x <- factor(sample(c("A", "B"), size = 500L, replace = TRUE, prob = c(0.9, 0.1)))
class_imbalance(x)

Run the code above in your browser using DataLab