How to specify positive label when use precision as scoring in GridSearchCV

Deadly 提交于 2019-12-24 14:11:44

问题


model = sklearn.model_selection.GridSearchCV(
        estimator = est, 
        param_grid = param_grid,
        scoring = 'precision',
        verbose = 1,
        n_jobs = 1,
        iid = True,
        cv = 3)

In sklearn.metrics.precision_score(y, y_pred,pos_label=[0]), I can specify the positive label, how can I specify this in GridSearchCV too?

If there is no way to specify, when using custom scoring, how can I define?

I have tried this:

custom_score = make_scorer(precision_score(y, y_pred,pos_label=[0]),  
                          greater_is_better=True)  

but I got error:

NameError: name 'y_pred' is not defined

回答1:


Reading the docs, you can pass any kwargs into make_scorer and they will be automatically passed into the score_func callable.

from sklearn.metrics import precision_score, make_scorer
custom_scorer = make_scorer(precision_score, greater_is_better=True,  pos_label=0)

Then you pass this custom_scorer to GridSearchCV:

gs = GridSearchCV(est, ..., scoring=custom_scorer)


来源:https://stackoverflow.com/questions/50933561/how-to-specify-positive-label-when-use-precision-as-scoring-in-gridsearchcv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!