You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RandomForestRegressor in GridSearchCV uses more cores than specified #12289
RandomForestRegressor in GridSearchCV uses more cores than specified.
importnumpyasnpfromsklearn.ensembleimportRandomForestRegressorfromsklearn.model_selectionimportGridSearchCVn_samples, n_features=10000, 10X=np.random.randn(n_samples, n_features)
y=np.random.randn(n_samples)
grid= {'n_estimators': [100, 200]}
# only one core is used (GOOD)rfr=RandomForestRegressor(n_estimators=100)
rfr.fit(X, y)
# only two cores are used (GOOD)rfr=RandomForestRegressor(n_estimators=100, n_jobs=1)
gsc=GridSearchCV(rfr, grid, n_jobs=2)
gsc.fit(X, y)
# more than two cores are used (BUG)rfr=RandomForestRegressor(n_estimators=100)
gsc=GridSearchCV(rfr, grid, n_jobs=2)
gsc.fit(X, y)
This is a bug from joblib indeed. It has to do with the prefer='threads'.
The RandomForestRegressor.fit method is called with a ThreadingBackend and n_jobs=-1, as the parameter prefer is passed to the Parallel instance. The RandomForestregressor.predict method is called using the SequentialBackend and the difference between these two calls is that the parameter prefer is not passed here.
I will further investigate and try to come up with a fix in joblib.
so we close this? Or wait for new joblib to be released / merged to scikit-learn? or wait for unvendoring? I'm not sure what to do with the rapid joblib changes wrt to releasing 0.20.1
Activity
tomMoral commentedon Oct 5, 2018
This is a bug from
joblibindeed. It has to do with theprefer='threads'.The
RandomForestRegressor.fitmethod is called with aThreadingBackendandn_jobs=-1, as the parameterpreferis passed to theParallelinstance. TheRandomForestregressor.predictmethod is called using theSequentialBackendand the difference between these two calls is that the parameterpreferis not passed here.I will further investigate and try to come up with a fix in
joblib.tomMoral commentedon Oct 5, 2018
I opened an issue in joblib/joblib#784 and a PR in joblib/joblib#785
amueller commentedon Oct 11, 2018
so we close this? Or wait for new joblib to be released / merged to scikit-learn? or wait for unvendoring? I'm not sure what to do with the rapid joblib changes wrt to releasing 0.20.1
ogrisel commentedon Nov 7, 2018
This was fixed by merging joblib 0.13.0 (I have just tried all the cases reported and by @TomDLT's snippet and they behave as expected).