我一直在下面的脚本中进行随机森林分类,并且遇到了一些与随机搜索的性能有关的问题-需要很长时间才能完成,我想知道我是否做错了什么或我可以做得更好以加快速度。
有人能提出我可以提高速度/性能的建议吗?
谢谢!
forest_start_time = time.time()
model = RandomForestClassifier()
param_grid = {
'bootstrap': [True, False],
'max_depth': [80, 90, 100, 110],
'max_features': [2, 3],
'min_samples_leaf': [3, 4, 5],
'min_samples_split': [8, 10, 12],
'n_estimators': [200, 300, 500, 1000]
}
bestforest = RandomizedSearchCV(estimator = model,
param_distributions = param_grid,
cv = 3, n_iter = 10,
n_jobs = available_processor_count)
bestforest.fit(train_features, train_labels.ravel())
forest_score = bestforest.score(test_features, test_labels.ravel())
print(forest_score)
forest_end_time = time.time()
forest_duration = forest_start_time-forest_end_time
答案 0 :(得分:1)
加快速度的唯一方法是1)减少功能或/和使用更多的CPU内核n_jobs = -1
:
bestforest = RandomizedSearchCV(estimator = model,
param_distributions = param_grid,
cv = 3, n_iter = 10,
n_jobs = -1)