并行运行 python vaex.ml.catboost.CatBoostModel.fit 数倍的正确方法是什么?

问题描述

说明

我有一个 python 代码,它顺序调用 vaex.ml.catboost.catboostModel.fit 3 次。 需要很多时间,我想并行运行vaex.ml.catboost.catboostModel.fit

问题

按顺序和并行运行 vaex.ml.catboost.catboostModel.fit 时得到不同的结果。当然,我做错了。我希望并行结果非常接近顺序结果(种子不是硬编码的,所以总会有一些小的波动)。顺序和并行版本产生绝对无法比拟的结果。

这是顺序代码。它产生 approved result

estimator = catboostModel(
        features=features + features_cat,target=target,num_boost_round=700,prediction_name="catboost_prediction",prediction_type=prediction_type
    )
 
for fold in folds:
    logging.info(f"training fold: {fold}")  # 1,2,3
    df_train = df[df.cv_fold != fold]
    df_val = df[df.cv_fold == fold]
    estimator.fit(df=df_train,evals=[df_val],early_stopping_rounds=100,verbose_eval=True)
    cv_scores[cv_fold == fold] = estimator.predict(df_val)

                

这是我的并行代码

import concurrent.futures
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
    future_to_result = {executor.submit(train_fold,fold,cv_scores,df,task,estimator): fold for fold in
                        folds}
    for future in concurrent.futures.as_completed(future_to_result):
        res = future_to_result[future]
        (fold,result) = future.result()
        logging.info(f"completed future for {fold},result: {result.shape}")
        cv_scores[cv_fold == fold] = result

def train_fold(fold,estimator: catboostModel):
    logging.info(f"training fold: {fold}")
    df_train = df[df.cv_fold != fold]
    df_val = df[df.cv_fold == fold]
    estimator.fit(df=df_train,verbose_eval=True)
    result = estimator.predict(df_val)

    return (fold,result)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...