Hi, I tried to use the fmin, but go the this error info.
Here is my code:
def lgbm_objective(params):
params = {
'num_leaves': int(params['num_leaves']),
'colsample_bytree': '{:.3f}'.format(params['colsample_bytree'])
}
reg = lgbm.LGBMRegressor(
n_estimators=500,
learning_rate=0.1,
**params
)
score = cross_val_score(reg, x_train, y_train, scoring=MSE_scorer(), cv=StratifiedKFold()).mean()
return score
lgbm_space = {
'max_depth': hp.quniform('max_depth', 8, 128, 2),
'colsample_bytree': hp.uniform('colsample_bytree', 0.3, 1.0),
}
lgbm_best = fmin(fn=lgbm_objective,
space=lgbm_space,
algo=tpe.suggest,
max_evals=10)
TypeError Traceback (most recent call last)
2 space=lgbm_space,
3 algo=tpe.suggest,
----> 4 max_evals=10)
C:Anaconda3libsite-packageshyperoptfmin.py 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,
C:Anaconda3libsite-packageshyperoptbase.py 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
C:Anaconda3libsite-packageshyperoptpyllbase.py 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 is not subscriptable
You can see issue: https://github.com/hyperopt/hyperopt/issues/325
And you can solve it by this cmd:$ pip install networkx==1.11
I also get this error even after doing pip install networkx==1.11:
TypeError Traceback (most recent call last)
4 algo=tpe.suggest,
5 max_evals=2,
----> 6 trials=trials)
7
8 print(best)
~/.envs/YM_py3.5/lib/python3.5/site-packages/hyperopt/fmin.py in fmin(fn, space, algo, max_evals, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin)
305 verbose=verbose,
306 catch_eval_exceptions=catch_eval_exceptions,
--> 307 return_argmin=return_argmin,
308 )
309
~/.envs/YM_py3.5/lib/python3.5/site-packages/hyperopt/base.py in fmin(self, fn, space, algo, max_evals, rstate, verbose, pass_expr_memo_ctrl, catch_eval_exceptions, return_argmin)
633 pass_expr_memo_ctrl=pass_expr_memo_ctrl,
634 catch_eval_exceptions=catch_eval_exceptions,
--> 635 return_argmin=return_argmin)
636
637
~/.envs/YM_py3.5/lib/python3.5/site-packages/hyperopt/fmin.py 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,
~/.envs/YM_py3.5/lib/python3.5/site-packages/hyperopt/base.py 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
~/.envs/YM_py3.5/lib/python3.5/site-packages/hyperopt/pyll/base.py 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 is not subscriptable
Restart the jupyter notebook after the installation
This was fixed in #319 but you'll either have to run with the code from the repository or wait for the next release.
Most helpful comment
You can see issue: https://github.com/hyperopt/hyperopt/issues/325
And you can solve it by this cmd:
$ pip install networkx==1.11