我想最大化一个功能:func(minCount, wordNgrams, lr, epoch, loss)
仅对这些值使用GridSearch:
`{'minCount': [2, 3],
'wordNgrams': [1, 2, 3, 4, 5],
'lr': [0.1, 0.01, 0.001, 0.0001],
'epoch': [5, 10, 15, 20, 25, 30],
'loss': [hs, ns, softmax]}`
我已经读过,sklearn.model_selection.GridSearchCV(estimator, param_grid, ...)
但是,我不知道我应该放在哪里func(minCount, wordNgrams, lr, epoch, loss)
顺便说一句,我已经阅读了贝叶斯优化(https://github.com/fmfn/BayesianOptimization),但是对如何与string
andint
参数一起使用却一无所知。
根据文档,您有两种解决方案:
def my_scoring_function(func_outputs):
"""
process the outputs of func and return a score.
if func already reutrns the value you want to minimize,
my_scoring_function will be the identity function.
score is the value to optimize
"""
return score
cv = GridSearchCV(estimator=func, param_grid=my_param_grid, scoring=my_scoring_function)
关于贝叶斯优化,如果您的问题满足以下条件,这将很有趣:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句