我在搜索空间定义的逻辑上遇到了麻烦。
我想搜索这些:
以下this example(页面上的第二篇文章,jacobzweig)
以及我设置的方式。def para_space():
space_paras = {'model_type': hp.choice('model_type', ['features_and_hours', 'features_only', 'hours_only', 'no_features_no_hours']),
'output_units': hp.uniform('output_units', 1, 10),
'kernel_reg': hp.choice('kernel_reg', [{'reg_type':'l1', 'reg_vals': hp.uniform('reg_vals', 0.0, 0.5)},
{'reg_type':'l2','reg_vals': hp.uniform('reg_vals', 0.0, 0.5)},
{'reg_type':'l1l2', 'reg_vals': hp.uniform('reg_vals', 0.0, 0.5)}]),
'activity_reg': hp.choice('activity_reg', [{'reg_type':'l1', 'reg_vals': hp.uniform('reg_vals', 0.0, 0.5)},
{'reg_type':'l2','reg_vals': hp.uniform('reg_vals', 0.0, 0.5)},
{'reg_type':'l1l2', 'reg_vals': hp.uniform('reg_vals', 0.0, 0.5)}]),
'num_epochs': hp.choice('num_epochs', [1, 5, 10]),
'optimizer': hp.choice('optimizer', ['adadelta', 'adam', 'rmsprop']),
'attention': hp.choice('attention', ['before', 'after', 'none'])}
return space_paras
我得到的错误是:
Using TensorFlow backend.
Traceback (most recent call last):
File "Jan22Model1.py", line 374, in <module>
best = fmin(lstm_model_1, params, algo=tpe.suggest, max_evals=5, trials=trials)
File "/user/pkgs/anaconda2/lib/python2.7/site-packages/hyperopt/fmin.py", line 307, in fmin
return_argmin=return_argmin,
File "/user/pkgs/anaconda2/lib/python2.7/site-packages/hyperopt/base.py", line 635, in fmin
return_argmin=return_argmin)
File "/user/pkgs/anaconda2/lib/python2.7/site-packages/hyperopt/fmin.py", line 314, in fmin
pass_expr_memo_ctrl=pass_expr_memo_ctrl)
File "/user/pkgs/anaconda2/lib/python2.7/site-packages/hyperopt/base.py", line 776, in __init__
raise DuplicateLabel(label)
hyperopt.exceptions.DuplicateLabel: reg_vals
但是在这个例子中,似乎有重复的标签不会引发错误。我做错了什么?
答案 0 :(得分:1)
我最终重组了这个空间,解决了这个问题:
def para_space():
space_paras = {'model_type': hp.choice('model_type', ['features_and_hours', 'features_only', 'hours_only', 'no_features_no_hours']),
'output_units': hp.uniform('output_units', 1, 10),
'kernel_reg': hp.choice('kernel_reg', ['l1', 'l2', 'l1_l2']),
'kernel_reg_value': hp.uniform('kernel_reg_value', 0.0, 0.5),
'activity_reg': hp.choice('activity_reg', ['l1', 'l2', 'l1_l2']),
'activity_reg_value': hp.uniform('activity_reg_value', 0.0, 0.5),
'optimizer': hp.choice('optimizer', ['adadelta', 'adam', 'rmsprop']),
'attention': hp.choice('attention', ['before', 'after', 'none'])}
return space_paras