gpt4 book ai didi

python - 为什么 GridSearchCV 在 { 'acquire' 对象的方法 'thread.lock'} 上花费超过 50% 的时间?

转载 作者:太空狗 更新时间:2023-10-29 21:03:32 24 4
gpt4 key购买 nike

最近我正在调整我的一些机器学习管道。我决定利用我的多核处理器。我使用参数 n_jobs=-1 运行交叉验证。我还对它进行了分析,令我惊讶的是:最重要的功能是:

{method 'acquire' of 'thread.lock' objects}

由于我在 Pipeline 中进行的操作,我不确定这是否是我的错。所以我决定做个小实验:

pp = Pipeline([('svc', SVC())])
cv = GridSearchCV(pp, {'svc__C' : [1, 100, 200]}, jobs=-1, cv=2, refit=True)
%prun cv.fit(np.random.rand(1e4, 100), np.random.randint(0, 5, 1e4))

输出是:

2691 function calls (2655 primitive calls) in 74.005 seconds
Ordered by: internal time

ncalls tottime percall cumtime percall filename:lineno(function)
83 43.819 0.528 43.819 0.528 {method 'acquire' of 'thread.lock' objects}
1 30.112 30.112 30.112 30.112 {sklearn.svm.libsvm.fit}

我想知道这种行为的原因是什么。如果有可能加快一点。

最佳答案

探查器只告诉你主进程在做什么,而它的子进程正在做所有的工作。在这种情况下,在 GridSearchCV 上设置 verbose=2 可能会提供比 %prun 更好的输出。

关于python - 为什么 GridSearchCV 在 { 'acquire' 对象的方法 'thread.lock'} 上花费超过 50% 的时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20072824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com