简体   繁体   English

我该如何处理多处理?

[英]How can I deal with multiprocessing?

I try to tune the learning rate parameter in XGBoost by using this part of program:我尝试使用这部分程序来调整 XGBoost 中的学习率参数:

model = XGBClassifier()
learning_rate = [0.0001, 0.001, 0.01, 0.1, 0.2, 0.3]
param_grid = dict(learning_rate=learning_rate)
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=7)
grid_search = GridSearchCV(model, param_grid, scoring="neg_log_loss", n_jobs=-1, cv=kfold)
grid_result = grid_search.fit(X, label_encoded_y)

but an error occurring in that line GridSearchCV: ImportError: [joblib] Attempting to do parallel computing without protecting your import on a system that does not support forking.但是在该行 GridSearchCV: ImportError: [joblib] 尝试在不支持分叉的系统上进行并行计算而不保护您的导入时发生错误。 To use parallel-computing in a script, you must protect your main loop using 'if name == ' main '.要在脚本中使用并行计算,您必须使用 'if name == ' main ' 保护您的主循环。

but when I change the value of n_jobs=-1 to n_jobs=1 the error goes out but I want it to run using all cores.但是当我将 n_jobs=-1 的值更改为 n_jobs=1 时,错误消失了,但我希望它使用所有内核运行。 please, how I can overcome this error?请问,我怎样才能克服这个错误?

将你的主循环(连同任何额外的必要代码)放在一个名为 main() 的函数中,并在你的脚本末尾放置if __name__ == '__main__': main()这样你就可以防止循环在以下情况下意外启动您将脚本内容导入其他程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM