# \[ANN\] Imbalance.jl - A well-documented, multi-interface and comprehensive Julia toolbox for addressing class imbalance

**URL:** https://discourse.julialang.org/t/ann-imbalance-jl-a-well-documented-multi-interface-and-comprehensive-julia-toolbox-for-addressing-class-imbalance/104825
**Category:** Package Announcements
**Tags:** package, announcement, machine-learning, mlj, classification
**Created:** [October 11, 2023, 2:19am UTC](https://discourse.julialang.org/t/ann-imbalance-jl-a-well-documented-multi-interface-and-comprehensive-julia-toolbox-for-addressing-class-imbalance/104825 "2023-10-11T02:19:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![EssamWisam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essamwisam/32/202386_2.png) [@EssamWisam](https://discourse.julialang.org/u/EssamWisam)
#### Post date: [October 11, 2023, 2:19am UTC](https://discourse.julialang.org/t/ann-imbalance-jl-a-well-documented-multi-interface-and-comprehensive-julia-toolbox-for-addressing-class-imbalance/104825/1 "2023-10-11T02:19:07Z")

</div>

Pleased to announce the [Imbalance.jl](https://github.com/JuliaAI/Imbalance.jl) package, a Julia-based toolkit featuring a wide range of established oversampling and undersampling techniques designed to tackle the class imbalance issue to improve classification model performance.

#### Features

- Supports multi-class variants of the algorithms and has methods that support both nominal and continuous features

- Supports table input/output formats as well as matrices

- Comprehensively documented with illustrative (visual) and practical examples for using the methods as shown method documentation and examples section.

- Provides `MLJ` and `TableTransforms` interfaces aside from the default pure functional interface for each method

- Ability to wrap an arbitrary number of resampling models with a classification model from `MLJ` using `MLJBalancing` to function as one unified model

You can read more about the package and its features in this Julia Forem [article](https://forem.julialang.org/essamwisam/class-imbalance-in-julia-3jek).

#### Acknowledgements

Sincere thanks go to Anthony Blaom (@ablaom) for being my mentor in Google Summer of Code where this project was proposed and special thanks also go to Rik Huijzer(@rikh) for his friendliness and the binary `SMOTE` implementation in `Resample.jl`.

P.S. I am restricted by the number of links that the post can include for being a new user on Discourse. Julia Forem article has more links.

---

<div class="post-metadata">

### Author: ![tecosaur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tecosaur/32/23206_2.png) [@tecosaur](https://discourse.julialang.org/u/tecosaur)
#### Post date: [October 11, 2023, 3:14am UTC](https://discourse.julialang.org/t/ann-imbalance-jl-a-well-documented-multi-interface-and-comprehensive-julia-toolbox-for-addressing-class-imbalance/104825/2 "2023-10-11T03:14:21Z")

</div>

Great stuff! It’s great to see the Statistical Learning ecosystem moving forwards one step at a time with packages like this and `StatisticalMeasures.jl` 😍.

One query, would this be able to compose with a stratified sampling scheme? A project I’m working on has two (extremely imbalanced) categories of data, and within each category there are blocks of (highly correlated) entries, and so I must employ a two-level sampling scheme where first I pick blocks, undersampling from the larger category, and then within each block randomly select an entry.

---

<div class="post-metadata">

### Author: ![EssamWisam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essamwisam/32/202386_2.png) [@EssamWisam](https://discourse.julialang.org/u/EssamWisam)
#### Post date: [October 11, 2023, 12:58pm UTC](https://discourse.julialang.org/t/ann-imbalance-jl-a-well-documented-multi-interface-and-comprehensive-julia-toolbox-for-addressing-class-imbalance/104825/3 "2023-10-11T12:58:29Z")

</div>

Glad to hear that you have liked it. Thank you.

> One query, would this be able to compose with a stratified sampling scheme?

It composes with anything that operates on (takes and returns) X, y data (where y can also be a column in X).

> A project I’m working on …

As far as I understand, the idea you are referring to here is [cluster sampling](https://en.wikipedia.org/wiki/Cluster_sampling). The naive `RandomUndersampler` provided in `Imbalance.jl` won’t help you do that, it will just delete examples randomly irrelevant of block in each class which would lead to the desired effect only if you have enough data. However, you can also try `ClusterUndersampler` which is pretty much cluster sampling done to each class, where the groups in each class are decided by k-means. Otherwise, for a hacky solution, if you perform naive random undersampling but have `X, y` where `X` is all the data in the majority category and `y` labels to what block each data point belongs to then you should be able to set the `ratios` hyperparameter to achieve your desired effect.

---

<div class="post-metadata">

### Author: ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)
#### Post date: [October 12, 2023, 11:20am UTC](https://discourse.julialang.org/t/ann-imbalance-jl-a-well-documented-multi-interface-and-comprehensive-julia-toolbox-for-addressing-class-imbalance/104825/4 "2023-10-12T11:20:03Z")

</div>

You had me at “well-documented” 😍 But seriously, awesome work!
