【问题标题】:Is it possible to combine multiple pipeline into single estimator in Neuraxle or sklearn to create multi-output classifer and fit in one go是否可以将多个管道组合到 Neuraxle 或 sklearn 中的单个估计器中以创建多输出分类器并一次性适应
【发布时间】:2021-07-06 04:38:50
【问题描述】:

我想创建多输出分类器。但是,我的问题是每个输出的正标签分布变化很大,例如对于输出 1,有 2% 的正标签,对于输出 2,有 20% 的正标签。因此,我想将每个输出的数据采样和模型拟合分离到多个流(多个子流水线)中,其中每个子流水线分别执行过采样,并且过采样和分类器的超参数也分别进行优化。

例如,假设我有

from sklearn.linear_model import LogisticRegression
from imblearn.over_sampling import SMOTE
from imblearn.pipeline import Pipeline

X = # some input features array here
y = np.array([[0,1],
              [0,1],
              [0,0],
              [1,0],
              [0,0]]) # unbalance label distribution

y_1 = y[:, 0]
y_2 = y[:, 1]


param_grid_shared = {'oversampler__sampling_strategy': [0.2, 0.4, 0.5], 'logit__C': [1, 0.1, 0.01]}

pipeline_output_1 = Pipeline([('oversampler', SMOTE()), ('logit', LogisticRegression())])
grid_1 = GridSearchCV(pipeline_output_1, param_grid_shared)
grid_1.fit(X, y_1)

pipeline_output_2 = Pipeline([('oversampler', SMOTE()), ('logit', LogisticRegression())])
grid_2 = GridSearchCV(pipeline_output_2, param_grid_shared)
grid_2.fit(X, y_2)

我想将它们结合起来创建类似的东西

multi_pipe = Pipeline([(Something to separate X and y into multiple streams)
                       ((pipe_1, pipeline_output_1),
                       (pipe_2, pipeline_output_2)), # 2 pipeline optimized separately
                       (Evaluate and select hyperparameters for each pipeline separately)
                       (Something to combine output from pipeline 1 and pipeline 2)
                      ]) 

在 Neuraxle 或 Sklearn 中

MultiOutputClassifier 肯定不适合这种情况,我现在不太确定去哪里寻找解决方案。

【问题讨论】:

  • 好问题!此处创建的问题:github.com/Neuraxio/Neuraxle/issues/473 一种解决方法是创建不同的数据采样器、不同的 AutoML 对象和指标,并使用两个不同的 AutoML 循环但使用相同的管道训练两个管道。数据采样器可以使用上下文服务中的数据存储(存储库)对多个输出进行不同的采样。尚未找到更好的解决方案。
  • 我还添加了以下问题,这是以下答案中描述的另一个想法:github.com/Neuraxio/Neuraxle/issues/474
  • @GuillaumeChevalier 谢谢。现在我将解决这个问题,并希望有新功能。

标签: python machine-learning scikit-learn neuraxle


【解决方案1】:

我创建了一个issue,想法如下:

pipe_1_with_oversampler_1 = Pipeline([
    Oversampler1().assert_has_services(DataRepository), Pipeline1()])
pipe_2_with_oversampler_2 = Pipeline([
    Oversampler2().assert_has_services(DataRepository), Pipeline2()])

multi_pipe = Pipeline([
    DataPreprocessingStep(),
    # Evaluate and select hyperparameters for each pipeline separately, but within one run, using `multi_pipe.fit(...)`: 
    FeatureUnion([
        AutoML(pipe_1_with_oversampler_1, **automl_args_1),
        AutoML(pipe_2_with_oversampler_2, **automl_args_2)
    ]),
    # And then combine output from pipeline 1 and pipeline 2 using feature union. 
    # Can do preprocessing and postprocessing as well.
    PostprocessingStep(),
])

为此,可以将 AutoML 对象重构为常规步骤,因此可以代替一个步骤使用。

【讨论】:

    猜你喜欢
    • 2015-06-15
    • 2020-12-26
    • 2022-09-28
    • 2019-11-02
    • 2016-01-18
    • 1970-01-01
    • 2016-07-06
    • 1970-01-01
    • 2019-01-08
    相关资源
    最近更新 更多