2

I have an imbalanced dataset and when I try to balance him using SMOTEENN, the count of majority class decreasing by half

I tried to change the 'sampling_strategy' parameter, with all the provided options but it not help

from imblearn.combine import SMOTEENN

sme = SMOTEENN()
X_res, y_res = sme.fit_resample(X_train, y_train)

print(f'Original train dataset shape: {Counter(y_train)}')
# Original train dataset shape: Counter({1: 2194, 0: 205})

print(f'Resampled train dataset shape: {Counter(y_res)}\n')
# Resampled train dataset shape: Counter({0: 2117, 1: 1226})
aynber
  • 22,380
  • 8
  • 50
  • 63
ZaKad
  • 41
  • 3

1 Answers1

0

If you look at the documentation SMOTEENN (https://imbalanced-learn.readthedocs.io/en/stable/generated/imblearn.combine.SMOTEENN.html#imblearn.combine.SMOTEENN ):

Combine over- and under-sampling using SMOTE and Edited Nearest Neighbours.

If you want to get an even number for each class you can try using other techniques like over_sampling.SMOTE

For example:

from sklearn.datasets import make_classification
from imblearn.combine import SMOTEENN
from imblearn.over_sampling import SMOTE
from collections import Counter

X, y = make_classification(n_samples=5000, n_features=2, n_informative=2,
                           n_redundant=0, n_repeated=0, n_classes=2,
                           n_clusters_per_class=1,
                           weights=[0.06, 0.94],
                           class_sep=0.1, random_state=0)


sme = SMOTEENN()
X_res, y_res = sme.fit_resample(X, y)

print(f'Original train dataset shape: {Counter(y)}')
# Original train dataset shape: Counter({1: 4679, 0: 321})

print(f'Resampled train dataset shape: {Counter(y_res)}\n')
# Resampled train dataset shape: Counter({0: 3561, 1: 3246})

sme = SMOTE()
X_res, y_res = sme.fit_resample(X, y)

print(f'Original train dataset shape: {Counter(y)}')
# Original train dataset shape: Counter({1: 4679, 0: 321})

print(f'Resampled train dataset shape: {Counter(y_res)}\n')
# Resampled train dataset shape: Counter({0: 4679, 1: 4679})
RyanL
  • 156
  • 1
  • 5
  • In your example, the size of the majority decreased in less and very close to the minority size, which does not happen in my example, even when the parameter sampling_strategy = 1.0 – ZaKad Apr 01 '19 at 20:29