使用scikit-learn parallel_backend时,可以通过n_jobs指定要运行的作业数:
from sklearn.externals import joblib
with joblib.parallel_backend(n_jobs=2):
searchcv_1.fit()
但是,由于我有多个内核,所以我想运行另一个独立的GridSearchCV:
from sklearn.externals import joblib
with joblib.parallel_backend(n_jobs=4): # increase n_jobs
searchcv_1.fit(X1, Y1)
searchcv_2.fit(X2, Y1)
当然,它仍然按顺序执行每个GridSearchCV,而不是为每个GridSearhCV分配两个内核。
我真正想要的是在单独的内核上执行两个GridSearchCV命令。我如何并行执行此操作?
from sklearn.externals import joblib
with joblib.parallel_backend(n_jobs=2):
searchcv_1.fit(X1, Y1)
# This is still sequential after searchcv_1.fit
with joblib.parallel_backend(n_jobs=2):
searchcv_2.fit(X2, Y1)