本文介绍了使用多个CPU的Scikit-learn机器学习模型训练的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用高端EC2实例来减少模型的训练时间.因此,我尝试使用2个CPU的 c5.18xlarge
实例,并使用参数 n_jobs = -1
运行一些模型,但我注意到仅使用了一个CPU:
I want to decrease training time of my models by using a high end EC2 instance. So I tried c5.18xlarge
instance with 2 CPUs and run a few models with parameter n_jobs=-1
but I noticed that only one CPU was utilized:
我可以以某种方式使Scikit学习使用所有CPU吗?
Can I somehow make Scikit-learn to use all CPUs?
推荐答案
尝试添加:
import multiprocessing
multiprocessing.set_start_method('forkserver')
在运行或导入任何内容之前,请先单击代码顶部的
.这是python中多处理的一个众所周知的问题.
at the top of your code, before running or importing anything. That's a well-known issue with multiprocessing in python.
这篇关于使用多个CPU的Scikit-learn机器学习模型训练的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!