CIGAN: A Python Package for Handling Class Imbalance using Generative Adversarial Networks

Yuxiao Huang, Yan MaarXiv 2022 · DOI · arXiv

Abstract

Class imbalance remains a significant hurdle in predictive modeling, often causing algorithms to overlook critical minority instances. We present CIGAN (Class Imbalance GAN), an open-source Python package designed to mitigate this issue through Generative Adversarial Networks. Unlike existing tools primarily focused on binary classification, CIGAN supports multi-class datasets. By training a generator to approximate the latent distribution of minority classes, CIGAN produces diverse synthetic samples that improve model generalization. Experimental results on the UCI Drug Consumption dataset show that CIGAN-augmented training significantly boosts recall and F1-scores for underrepresented classes compared to imbalanced baselines.

Introduction

In machine learning, class imbalance occurs when the majority class significantly outnumbers minority classes. This is particularly problematic in high-stakes domains like healthcare; for instance, a model trained on a dataset where 99% of patients are healthy may achieve high accuracy by simply ignoring the 1% who are sick. Traditional solutions, such as the SMOTE algorithm, rely on oversampling through interpolation. However, these methods often produce data too similar to existing samples, leading to overfitting.

CIGAN addresses these limitations by leveraging the power of Generative Adversarial Networks (GANs) to learn the underlying statistical distribution of data, allowing for the generation of realistic and diverse synthetic samples. Crucially, CIGAN fills a gap in the current software ecosystem by providing native support for multi-class problems.

The CIGAN Framework

CIGAN utilizes a standard GAN architecture consisting of two competing neural networks: the Generator and the Discriminator. The Generator attempts to create synthetic data samples that mimic the minority class distribution, while the Discriminator attempts to distinguish between real data and these synthetic "fakes."

The two-stage adversarial training process of CIGAN.

As shown in the figure above, the training progresses through two stages. In Stage 1, the Generator's output is easily distinguishable from the real data. Through an iterative adversarial "game," the Generator learns to produce data so realistic that by Stage 2, the Discriminator can no longer reliably tell the difference, reaching a Nash Equilibrium. The authors recommend a specific architectural "shape" for these networks: the generator should utilize an ascending layer size (widening toward the output), while the discriminator should use a descending layer size.

Implementation Pipeline

CIGAN is designed for ease of use, featuring a Scikit-Learn-like API that allows researchers to resample datasets with minimal code. The package is highly tunable, exposing 16 parameters including learning rates and optimizer types.

The end-to-end machine learning workflow using CIGAN for data augmentation.

The standard workflow involves three steps. First, the imbalanced data is preprocessed and split into training, validation, and test sets. Second, CIGAN is trained on the imbalanced training data to generate synthetic samples, resulting in a balanced training set. Finally, a classifier is trained on this balanced data, validated, and evaluated against the original imbalanced test set to ensure real-world performance gains.

Experimental Evaluation

The package was evaluated using the Drug Consumption (DC) dataset from the UCI Machine Learning Repository, specifically focusing on Amphetamine use. The data was categorized into three classes: "Never Used" (52%), "Used over a Decade Ago" (12%), and "Used in Last Decade" (36%). Class 2 represented a clear minority, posing a significant challenge for standard classifiers.

A HistGradientBoostingClassifier (HGBC) was used as the baseline. When trained on CIGAN-augmented data, the model showed substantial improvements across all metrics for the minority class:

  • Recall: Increased from 0.116 to 0.246, more than doubling the model's ability to identify minority class members.
  • F1-Score: Improved from 0.168 to 0.318.
  • Consistency: CIGAN outperformed the baseline in Precision, Recall, and F1-score for every class in the dataset.

Conclusion and Future Work

CIGAN provides a robust, user-friendly tool for addressing multi-class imbalance by learning latent distributions rather than simple interpolation. While the current version defaults to a 1:1 class balance, future work will investigate the "optimal degree" of augmentation—determining if partial balancing (e.g., 80% or 90% of the majority class size) might further maximize classification power and prevent potential overfitting in specific contexts.

Summary updated

BibTeX
@misc{huang2022cigan,
  author = {Yuxiao Huang and Yan Ma},
  title = {{CIGAN: A Python Package for Handling Class Imbalance using Generative Adversarial Networks}},
  year = {2022},
  eprint = {2208.02931},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2208.02931},
}
Figure