ufoym/imbalanced-dataset-sampler
A (PyTorch) imbalanced dataset sampler for oversampling low frequent classes and undersampling high frequent ones.
What it solves
It addresses the problem of class imbalance in machine learning datasets, where some categories are over-represented and others are under-represented. This imbalance often leads models to be biased toward the majority class, resulting in poor performance on rare but critical samples (e.g., rare diseases).
How it works
The project provides a PyTorch sampler called ImbalancedDatasetSampler. Instead of manually creating a new balanced dataset via under-sampling or over-sampling, this sampler automatically estimates sampling weights based on class appearance probability. It then weighs samples inversely to their probability, ensuring the model sees a balanced distribution of classes during training.
Who it’s for
Machine learning practitioners using PyTorch who need to handle imbalanced datasets without the risk of overfitting caused by simple duplication or the information loss caused by random removal of data.
Highlights
- Automatically estimates sampling weights for class rebalancing.
- Integrates directly into the PyTorch
DataLoaderas a sampler. - Avoids the need to create a separate, physically balanced dataset.
- Works effectively with data augmentation to mitigate overfitting.
Related
- Project
- Project
- Project
- Project