我们如何在 SMOTE 中设置比率以使正样本多于负样本?

How do we set ratio in SMOTE to have more positive sample than negative sample?

我正在尝试使用 SMOTE 来处理二进制 class 化的不平衡 class 数据,我所知道的是:如果我们使用,例如

sm = SMOTE(ratio = 1.0, random_state=10)

Before OverSampling, counts of label '1': [78]
Before OverSampling, counts of label '0': [6266] 

After OverSampling, counts of label '1': 6266
After OverSampling, counts of label '0': 6266

对于 class 1 是少数的情况,它将导致 50:50 数量的 class 0 和 1

sm = SMOTE(ratio = 0.5, random_state=10)

Before OverSampling, counts of label '1': [78]
Before OverSampling, counts of label '0': [6266] 

After OverSampling, counts of label '1': 3133
After OverSampling, counts of label '0': 6266

将导致 class 1 的大小减半 class 0。

我的问题:

我们如何设置比率以获得比class 0更多的class 1,例如75:25?

docs 看来,ratio 可以是大于 1 的浮点数 - 即对于 75:25 比率,您可以设置 ratio=3
尝试看看是否有效。

尝试使用字典。

smote_on_1 = 18798 
#(In your case 18798 is thrice of 6266)

smt = SMOTE(sampling_strategy={1: smote_on_1})
X_train, y_train = smt.fit_sample(X_train, y_train)