我遇到了一个奇怪的问题:我通过 hyperopt
定义了我的 XGB 超参数'max_depth'
hp.choice('max_depth',range(2,20))
Run Code Online (Sandbox Code Playgroud)
但我得到'max_depth' = 0或1结果,这不在[2,20)限制之内。为什么?我错过了什么吗?谢谢。
错误结果:
{'colsample_bytree': 0.18, 'learning_rate': 0.05, 'max_depth': 1, 'reg_alpha': 3.44, 'reg_lambda': 0.92}
{'colsample_bytree': 0.41, 'learning_rate': 0.09, 'max_depth': 0, 'reg_alpha': 0.14, 'reg_lambda': 3.53}
{'colsample_bytree': 0.71, 'learning_rate': 0.17, 'max_depth': 0, 'reg_alpha': 2.21, 'reg_lambda': 2.82}
Run Code Online (Sandbox Code Playgroud)
hp.choice('max_depth',range(2,20))
Run Code Online (Sandbox Code Playgroud)
我也面临同样的问题。这不是一个错误。
从官方文档来看hyperopt,是无法理解的。但是zilin xiang 的回答和ncalik的很好的解释帮助我理解了出现问题的原因。这帮助我解决了问题。
问题发生的原因
这是由于使用hp.choice()和未return_argmin=False在fmin(). 由于您设置了max_depth[2,20),因此获取索引 0 或 1 意味着它正在使用max_depth2(对于索引 0)或 3(对于索引 1)。
解决问题
如果你想获取实际参数而不是索引,那么,你可以使用两种方法。
hyperopt.space_eval():hyperopt.space_eval(space, best_param)。return_argmin=False于fmin():best_param=fmin(xgb_classifier_tune,space,algo=tpe.suggest,max_evals=100, trials=trials, return_argmin=False). 它将返回参数的实际值,而不是索引。要了解更多信息,您可以查看此。
| 归档时间: |
|
| 查看次数: |
1438 次 |
| 最近记录: |