【问题标题】:How do we set ratio in SMOTE to have more positive sample than negative sample?我们如何在 SMOTE 中设置比率以使正样本多于负样本?
【发布时间】:2019-09-08 03:42:23
【问题描述】:

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

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

对于 1 类为少数的情况,将导致 0 类和 1 类的数量为 50:50

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

将导致类 1 的大小减半。

我的问题:

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

【问题讨论】:

    标签: python pandas scikit-learn preprocessor smote


    【解决方案1】:

    尝试使用字典。

    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)
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我假设你正在使用 SMOTE 的这个实现,或者一个足够相似的实现;如果没有,请在您的问题中指定您使用的是哪种实现。如果您使用的实现是如此常见以至于我应该知道,请赐教(我真的不知道,我不是在讽刺)。
      • 我试过了。但是得到了这个信息:当 'sampling_strategy' 是一个浮点数时,它应该在 (0, 1] 范围内,所以 mx 是 1.0
      • 您可以做的另一件事是发送dict 并提供所需数量的样本。再次来自文档:“当 dict 时,键对应于目标类。值对应于每个目标类的所需样本数。”
      猜你喜欢
      • 2020-07-05
      • 1970-01-01
      • 2018-12-31
      • 2021-11-14
      • 1970-01-01
      • 2019-08-30
      • 1970-01-01
      • 2019-09-29
      • 1970-01-01
      相关资源
      最近更新 更多