将闭包作为记分员传递给GridSearchCV

时间:2018-07-09 20:38:41

标签: python scikit-learn

我有一个使用闭包定义的自定义评分器:

def myScorer(lmbda):
    _lambda=lmbda
    def _myScore(y_true,y_pred, **kwargs):
        ... do some math on y_true,y_pred using _lambda ...
        return score
    return _myScore

custom_scorer = make_scorer(myScorer(0.1))  

search = GridSearchCV(learner, params, cv=3, n_jobs=-1, scoring=custom_scorer)

运行代码时,我遇到了一个腌制错误: AttributeError: Can't pickle local object 'myScorer.<locals>._myScore'

将lambda硬编码到我的自定义评分功能中,有什么办法可以解决酸洗问题?将myScorer重新定义为课程会有帮助吗?

0 个答案:

没有答案