gpt4 book ai didi

python - 使用贝叶斯优化时队列为空

转载 作者:行者123 更新时间:2023-12-04 15:35:08 25 4
gpt4 key购买 nike

我正在使用贝叶斯优化来优化使用 python 库“bayes_opt”的神经网络的超参数,但出现错误

~\Miniconda3\envs\tensorflow\lib\site-packages\bayes_opt\bayesian_optimization.py in next(self) 25 if self.empty: ---> 26 raise StopIteration("Queue is empty, no more objects to retrieve.") 27 obj = self._queue[0]

StopIteration: Queue is empty, no more objects to retrieve.

我的代码如下:

from bayes_opt import BayesianOptimization
import time

# Supress NaN warnings, see: https://stackoverflow.com/questions/34955158/what-might-be-the-cause-of-invalid-value-encountered-in-less-equal-in-numpy
import warnings
warnings.filterwarnings("ignore",category =RuntimeWarning)


# Bounded region of parameter space
pbounds = {'dropout': (0.0, 0.499),
'lr': (0.0, 0.1),
'neuronPct': (0.01, 1),
'neuronShrink': (0.01, 1)
}

optimizer = BayesianOptimization(
f=evaluate_network,
pbounds=pbounds,
verbose=2, # verbose = 1 prints only when a maximum is observed, verbose = 0 is silent
random_state=1,
)

start_time = time.time()
optimizer.maximize(init_points=10, n_iter=100,)
time_took = time.time() - start_time

print(optimizer.max)

输出如下:

|   iter    |  target   |  dropout  |    lr     | neuronPct | neuron... |
-------------------------------------------------------------------------
| 1 | -0.5718 | 0.2081 | 0.07203 | 0.01011 | 0.3093 |
| 2 | -0.5906 | 0.07323 | 0.009234 | 0.1944 | 0.3521 |
| 3 | -2.475 | 0.198 | 0.05388 | 0.425 | 0.6884 |
| 4 | -0.5708 | 0.102 | 0.08781 | 0.03711 | 0.6738 |
| 5 | -0.5749 | 0.2082 | 0.05587 | 0.149 | 0.2061 |
| 6 | -2.487 | 0.3996 | 0.09683 | 0.3203 | 0.6954 |
| 7 | -0.5669 | 0.4373 | 0.08946 | 0.09419 | 0.04866 |
| 8 | -0.5701 | 0.08475 | 0.08781 | 0.1074 | 0.4269 |
| 9 | -0.607 | 0.478 | 0.05332 | 0.695 | 0.3224 |
| 10 | -0.581 | 0.3426 | 0.08346 | 0.02811 | 0.7526 |
| 11 | -0.7295 | 0.1606 | 0.0 | 1.0 | 0.01 |
| 12 | -0.7131 | 0.499 | 0.0 | 0.607 | 0.01 |
| 13 | -0.7044 | 0.0 | 0.0 | 0.01 | 0.01 |
| 14 | -0.5872 | 0.04935 | 0.01347 | 0.4728 | 0.4246 |
| 15 | -0.5665 | 0.0 | 0.1 | 0.5566 | 0.01 |
| 16 | -0.9658 | 0.0 | 0.0 | 1.0 | 0.4938 |
| 17 | -0.9074 | 0.0 | 0.0 | 0.01 | 1.0 |
| 18 | -2.464 | 0.499 | 0.1 | 1.0 | 0.1975 |
| 19 | -0.9505 | 0.499 | 0.0 | 1.0 | 1.0 |
| 20 | nan | 0.0 | 0.1 | 1.0 | 1.0 |

注意输出表最后一行的“nan”
提前致谢。

最佳答案

同样的事情发生在我身上。我看到这是一篇旧帖子,所以不希望很快找到解决方案。

我设法将其缩小到以下范围:如果 pbounds 间隔太小,就会发生这种情况。我使 pbound 间隔稍微大一点,它就停止了。

这对我有用,但我希望将来某个时候有人能解决这个问题。错误似乎在 sklearn 中。

关于python - 使用贝叶斯优化时队列为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60045053/

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