# Upsampling and downsampling in Julia for unbalanced classes

**URL:** https://discourse.julialang.org/t/upsampling-and-downsampling-in-julia-for-unbalanced-classes/16856
**Category:** General Usage
**Tags:** question, package
**Created:** [October 27, 2018, 10:07am UTC](https://discourse.julialang.org/t/upsampling-and-downsampling-in-julia-for-unbalanced-classes/16856 "2018-10-27T10:07:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ajaychat3](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)
#### Post date: [October 27, 2018, 10:07am UTC](https://discourse.julialang.org/t/upsampling-and-downsampling-in-julia-for-unbalanced-classes/16856/1 "2018-10-27T10:07:16Z")

</div>

I use Imblearn package in python to do upsampling and downsampling for unbalanced classification problem.

Is there a simple way to accomplish this in Julia?

---

<div class="post-metadata">

### Author: ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)
#### Post date: [October 27, 2018, 10:47am UTC](https://discourse.julialang.org/t/upsampling-and-downsampling-in-julia-for-unbalanced-classes/16856/2 "2018-10-27T10:47:03Z")

</div>

you can try if this does what you need

[https://mldatapatternjl.readthedocs.io/en/latest/documentation/targets.html#under-and-over-sampling](https://mldatapatternjl.readthedocs.io/en/latest/documentation/targets.html#under-and-over-sampling)

---

<div class="post-metadata">

### Author: ![Ajaychat3](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)
#### Post date: [October 27, 2018, 11:37am UTC](https://discourse.julialang.org/t/upsampling-and-downsampling-in-julia-for-unbalanced-classes/16856/3 "2018-10-27T11:37:17Z")

</div>

Thanks. Yes this is exactly what I looking for.

---

<div class="post-metadata">

### Author: ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)
#### Post date: [May 26, 2019, 3:37am UTC](https://discourse.julialang.org/t/upsampling-and-downsampling-in-julia-for-unbalanced-classes/16856/4 "2019-05-26T03:37:54Z")

</div>

You might also find the [ClassImbalance.jl](https://github.com/bcbi/ClassImbalance.jl) package useful. It offers the SMOTE and ROSE algorithms, which are often more effective than simple oversampling and undersampling.

(Disclosure: I am one of the maintainers of [ClassImbalance.jl](https://github.com/bcbi/ClassImbalance.jl).)

---

<div class="post-metadata">

### Author: ![EmanuelCastanho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emanuelcastanho/32/45245_2.png) [@EmanuelCastanho](https://discourse.julialang.org/u/EmanuelCastanho)
#### Post date: [December 29, 2022, 11:20am UTC](https://discourse.julialang.org/t/upsampling-and-downsampling-in-julia-for-unbalanced-classes/16856/5 "2022-12-29T11:20:04Z")

</div>

How to under sample only the majority class?  
For example:  
Class 1 has 200.000 points;  
Class 2 has 10.000 points;  
Class 3 has 5.000 points.

How can I target only Class 1 to have 10.000 points?
