在管道中使用 SMOTEN

数据挖掘 阶级失衡 打击 不平衡学习 smotenc
2022-02-13 15:51:36

我正在尝试找出构建管道以训练模型的适当方法,其中包括使用 SMOTENC 算法:

  1. 鉴于使用了 N-Nearest Neighbors 算法和欧几里得距离,应将数据归一化(将输入向量单独缩放到单位范数)。在管道中应用 SMOTEN 之前?

  2. 该算法可以处理缺失值吗?如果基于中位数和百分位数的数据插补和异常值删除是在 SMOTENC 之前而不是之后执行的,这不会影响插补/百分位数吗?

  3. 可以在 one-hot 编码并将数字二进制列定义为分类特征后应用 SMOTEN 吗?

  4. 当管道包含在交叉验证模式中时,数据平衡是否仅适用于不平衡的训练折叠或测试折叠?

这是我的管道当前的样子:

from imblearn.pipeline import Pipeline as Pipeline_imb
from imblearn.over_sampling import SMOTENC

categorical_features_bool = [True, True, ……. False, False]
smt = SMOTENC(categorical_features =categorical_features_bool, 
                random_state=RANDOM_STATE_GRID,
                k_neighbors=10
                ,n_jobs=-1
                     )

preprocess_pipeline = ColumnTransformer(
        transformers=[
            ('Winsorize', FunctionTransformer(winsorize, validate=False, 
                                              kw_args={'limits':[0, 0.02],'inplace':False,'axis':0}), 
             ['feat_1,'Feat_2']),

            ('num_impute', SimpleImputer(strategy='median', add_indicator=True) , 
             ['feat_10,'Feat_15']),
        ], remainder='passthrough', #passthough features not listed
        n_jobs=-1,
        verbose = False
    )

Model = LogisticRegression()

model_pipeline = Pipeline_imb([
            ('preprocessing', preprocess_pipeline),
            ('smt', smt),
            ('Std', StandardScaler()),
            ('classifier', Model)
            ])
1个回答
  1. 欧几里得距离的通常归一化不是将每个输入缩放到单位长度,而是将每一缩放为均值 0 和方差 1。每个数据的缩放是可能的,但并不常见。

  2. 我不知道

  3. SMOTENC 的全部意义在于进行 one-hot 编码。一种热编码是一种将分类数据转换为数字数据(在多个维度上)的方法,用于无法处理分类数据的算法。所以我的建议是不要转换分类列并让 SMOTENC 处理它们

  4. imblearn 中的 Pipeline 做了正确的事情——它只在训练集上应用过采样(其他不平衡策略)而不是在测试集上。在 StackOverflow 中查看这个问题:https ://stackoverflow.com/questions/63520908/does-imblearn-pipeline-turn-off-sampling-for-testing