Closed
Description
RandomForestRegressor
in GridSearchCV
uses more cores than specified.
import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import GridSearchCV
n_samples, n_features = 10000, 10
X = 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)