imbalanced-learn

Resampling toolkit for handling imbalanced datasets in machine learning

pipmacoslinuxwindows
Try with needOr install directly
Source

About

Toolbox for imbalanced dataset in machine learning

Examples

oversample minority class in imbalanced dataset$ python -c "from imblearn.over_sampling import SMOTE; smote = SMOTE(); X_resampled, y_resampled = smote.fit_resample(X, y)"
undersample majority class to balance training data$ python -c "from imblearn.under_sampling import RandomUnderSampler; rus = RandomUnderSampler(); X_resampled, y_resampled = rus.fit_resample(X, y)"
combine oversampling and undersampling techniques$ python -c "from imblearn.pipeline import Pipeline; from imblearn.over_sampling import SMOTE; from imblearn.under_sampling import TomekLinks; pipe = Pipeline([('smote', SMOTE()), ('tomek', TomekLinks())])"
evaluate classifier performance on imbalanced data$ python -c "from imblearn.metrics import classification_report_imbalanced; print(classification_report_imbalanced(y_true, y_pred))"
create balanced cross validation splits for training$ python -c "from imblearn.datasets import make_imbalance; from sklearn.model_selection import cross_validate; X, y = make_imbalance(X, y, sampling_strategy=0.5)"