我正在尝试第一次使用hyperopt。我复制并粘贴了教程示例:
from hyperopt import fmin, tpe, hp
best = fmin(fn=lambda x: x ** 2,
space=hp.uniform('x', -10, 10),
algo=tpe.suggest,
max_evals=100)
print best
但这给了我:
TypeError Traceback (most recent call last)
<ipython-input-1-c6ddf657bb46> in <module>()
3 space=hp.uniform('x', -10, 10),
4 algo=tpe.suggest,
----> 5 max_evals=100)
6 print best
/home/user/.local/lib/python2.7/site-packages/hyperopt/fmin.pyc in fmin(fn, space, algo, max_evals, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin)
312
313 domain = base.Domain(fn, space,
--> 314 pass_expr_memo_ctrl=pass_expr_memo_ctrl)
315
316 rval = FMinIter(algo, domain, trials, max_evals=max_evals,
/home/user/.local/lib/python2.7/site-packages/hyperopt/base.pyc in __init__(self, fn, expr, workdir, pass_expr_memo_ctrl, name, loss_target)
784 before = pyll.dfs(self.expr)
785 # -- raises exception if expr contains cycles
--> 786 pyll.toposort(self.expr)
787 vh = self.vh = VectorizeHelper(self.expr, self.s_new_ids)
788 # -- raises exception if v_expr contains cycles
/home/user/.local/lib/python2.7/site-packages/hyperopt/pyll/base.pyc in toposort(expr)
713 G.add_edges_from([(n_in, node) for n_in in node.inputs()])
714 order = nx.topological_sort(G)
--> 715 assert order[-1] == expr
716 return order
717
TypeError: 'generator' object has no attribute '__getitem__'
我不太确定此错误消息的含义。
我究竟做错了什么?
最佳答案
hyperopt
当前与NetworkX 2.x不兼容。 The master branch should have the fix,但没有固定的hyperopt
版本。
现在,您要么必须从master分支安装hyperopt
,要么降级到NetworkX的1.x版本。