You can install the released version of themis from CRAN with:
Install the development version from GitHub with:
Following is a example of using the SMOTE algorithm to deal with unbalanced data
library(recipes) library(modeldata) library(themis) data(okc) sort(table(okc$Class, useNA = "always")) #> #> <NA> stem other #> 0 9539 50316 ds_rec <- recipe(Class ~ age + height, data = okc) %>% step_meanimpute(all_predictors()) %>% step_smote(Class) %>% prep() #> Warning: `step_meanimpute()` was deprecated in recipes 0.1.16. #> Please use `step_impute_mean()` instead. sort(table(bake(ds_rec, new_data = NULL)$Class, useNA = "always")) #> #> <NA> stem other #> 0 50316 50316
Below is some unbalanced data. Used for examples latter.
The following methods all share the tuning parameter
over_ratio, which is the ratio of the majority-to-minority frequencies.
|Random minority over-sampling with replacement||
|Synthetic Minority Over-sampling Technique||
|Adaptive synthetic sampling approach for imbalanced learning||
|Generation of synthetic data by Randomly Over Sampling Examples||
over_ratio = 1 you bring the number of samples of all minority classes equal to 100% of the majority class.
and by setting
over_ratio = 0.5 we upsample any minority class with less samples then 50% of the majority up to have 50% of the majority.
Most of the the following methods all share the tuning parameter
under_ratio, which is the ratio of the minority-to-majority frequencies.
|Random majority under-sampling with replacement||
|Extraction of majority-minority Tomek links||
under_ratio = 1 you bring the number of samples of all majority classes equal to 100% of the minority class.
and by setting
under_ratio = 2 we downsample any majority class with more then 200% samples of the minority class down to have to 200% samples of the minority.
This project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
For questions and discussions about tidymodels packages, modeling, and machine learning, join us on RStudio Community.
If you think you have encountered a bug, please submit an issue.
Either way, learn how to create and share a reprex (a minimal, reproducible example), to clearly communicate about your code.