【发布时间】:2017-12-06 02:48:29
【问题描述】:
我正在使用GridSearchCV 寻找RandomForestClassifier 的最佳参数
这是部分代码:
clf = RandomForestClassifier(n_jobs=-1)
param_grid = {"max_depth": [3, None],
"max_features": [1, 3, 10],
"min_samples_split": [2, 3, 10],
"min_samples_leaf": [1, 3, 10],
"bootstrap": [True, False],
"criterion": ["gini", "entropy"]}
# run grid search
grid_search = GridSearchCV(clf, param_grid=param_grid, n_jobs=-1)
start = time.time()
grid_search.fit(X_train, y_train)
print("GridSearchCV took %.2f seconds for %d candidate parameter settings."
% (time.time() - start, len(grid_search.cv_results_['params'])))
我在 32 核服务器上运行此代码,但使用 htop 我看到只有大约 8 个内核在使用,所以我的问题是如何启用所有内核?
【问题讨论】:
-
将
n_jobs显式设置为32? -
@cᴏʟᴅsᴘᴇᴇᴅ 效果与
n_jobs=-1相同
标签: python machine-learning scikit-learn random-forest