python - 如何在 scikit-learn 或 Neuraxle 中并行运行 2 个管道?

标签 python machine-learning scikit-learn pipeline neuraxle

我想用 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' object has no attribute 'setup'

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

最佳答案

是的!你可以这样做:

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) ?可能是 Neuraxle 没有将该模型识别为 scikit-learn 模型(它是 scikit-learn 中的 BaseEstimator 对象),即使您的对象具有与 scikit-learn 的 BaseEstimator 相同的 API。因此,您可能需要围绕您的模型手动使用 SKLearnWrapper 或编写您自己的类似包装器以使您的类适应 Neuraxle。

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


编辑:

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

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

关于python - 如何在 scikit-learn 或 Neuraxle 中并行运行 2 个管道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60080806/

相关文章:

Python 继承基于 __init__ 值的魔术方法

python - 根据元素距离交错两个 numpy 数组(python)

python - 日期时间类型错误: not all arguments converted during string formatting

python - 如何在当前的词袋分类中添加另一个文本特征?在 Scikit-learn 中

python - 执行 StandardScaler 后将 NaN 分配给 -1

python-3.x - sklearn 的 log_loss 给出了 nan,而 tensorflow.losses.log_loss 有效

python - 通过间隙统计和预测强度估计集群数量

machine-learning - 从 3D 模型制作经过训练的模型(机器学习)

python - 如何将 theano 中函数返回的矩阵或向量打印到屏幕?

python - 缺少类别的单热编码