【问题标题】:How to run 2 pipelines in parallel in scikit-learn or Neuraxle?如何在 scikit-learn 或 Neuraxle 中并行运行 2 个管道?
【发布时间】:2020-05-21 15:55:18
【问题描述】:

我想用neuraxle 创建一个简单的管道(我知道我可以使用其他库,但我想使用neuraxle),我想在其中清理数据、拆分数据、训练 2 个模型并进行比较。

我希望我的管道做这样的事情:

p = Pipeline([
    PreprocessData(),
    SplitData(),
    (some magic to start the training of both models with the split of the previous step)
    ("model1", model1(params))
    ("model2", model2(params))
    (evaluate)
])

我什至不知道这是否可能,因为我在文档中找不到任何内容。

我还尝试使用 sklearn 以外的其他模型(例如 catboostxgboost ...),但我得到了错误

AttributeError: 'CatBoostRegressor' 对象没有属性 'setup'

我想过为模型创建一个类,但我不会使用neuraxle 的超参数搜索

【问题讨论】:

  • 始终共享整个错误消息。

标签: python machine-learning scikit-learn pipeline neuraxle


【解决方案1】:

是的!你可以这样做:

p = Pipeline([
    PreprocessData(),
    ColumnTransformer([
        (0, model1(params)),  # Model 1 will receive Column 0 of data
        ([1, 2], model2(params)),  # Model 2 will receive Column 1 and 2 of data
    ], n_dimension=2, n_jobs=2),
    (evaluate)
])

数据流将一分为二。

n_jobs=2 应该创建两个线程。也可以使用joiner 参数传递一个自定义类以将数据重新组合在一起。我们将很快发布一些更改,所以这应该可以正常工作。目前,管道使用 1 个线程。

对于你的CatBoostRegressor 模型,它类似于 sklearn 但不是来自 sklearn,你可以在管道中声明你的模型时尝试做 SKLearnWrapper(model1(params)) 而不是简单的 model1(params) 吗?即使您的对象具有与 scikit-learn 的 BaseEstimator 相同的 API,Neuraxle 也可能不会将该模型识别为 scikit-learn 模型(它是 scikit-learn 中的 BaseEstimator 对象)。因此,您可能需要在模型周围手动使用SKLearnWrapper,或者编写自己的类似包装器以使您的类适应 Neuraxle。

相关:https://stackoverflow.com/a/60302366/2476920


编辑

您可以使用 Neuraxle 的 ParallelQueuedFeatureUnion 类。示例即将推出。

另请参阅此并行管道使用示例:https://www.neuraxle.org/stable/examples/parallel/plot_streaming_pipeline.html#sphx-glr-examples-parallel-plot-streaming-pipeline-py

【讨论】:

    猜你喜欢
    • 2015-08-14
    • 2020-09-22
    • 2018-07-29
    • 2021-08-15
    • 2021-03-17
    • 2016-12-16
    • 2015-06-23
    • 1970-01-01
    相关资源
    最近更新 更多