【问题标题】:RandomSearchCV super slow - troubleshooting performance enhancementRandomSearchCV 超慢 - 故障排除性能增强
【发布时间】:2019-11-04 16:52:42
【问题描述】:

我一直在编写以下随机森林分类脚本,但遇到了一些与随机搜索性能相关的问题 - 这需要很长时间才能完成,我想知道我做错了什么或者我可以做得更好以使其更快。

有人能建议我可以改进速度/性能吗?

提前致谢!

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

【问题讨论】:

标签: python-3.x scikit-learn random-forest


【解决方案1】:

加快速度的唯一方法是 1) 减少功能或/和使用更多 CPU 内核 n_jobs = -1:

bestforest = RandomizedSearchCV(estimator = model, 
                                param_distributions = param_grid, 
                                cv = 3, n_iter = 10, 
                                n_jobs = -1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-21
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 2021-02-28
    • 1970-01-01
    相关资源
    最近更新 更多