【问题标题】:How to specify positive label when use precision as scoring in GridSearchCV在 GridSearchCV 中使用精度作为评分时如何指定正标签
【发布时间】:2018-11-28 17:19:29
【问题描述】:
model = sklearn.model_selection.GridSearchCV(
        estimator = est, 
        param_grid = param_grid,
        scoring = 'precision',
        verbose = 1,
        n_jobs = 1,
        iid = True,
        cv = 3)

sklearn.metrics.precision_score(y, y_pred,pos_label=[0]) 中,我可以指定正标签,如何在 GridSearchCV 中也指定?

如果没有办法指定,在使用自定义评分时,我该如何定义?

我试过这个:

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

但我得到了错误:

NameError: name 'y_pred' is not defined

【问题讨论】:

    标签: scikit-learn grid-search scoring


    【解决方案1】:

    读取docs,您可以将任何kwargs 传递给make_scorer,它们将自动传递给score_func 可调用对象。

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

    然后你将这个custom_scorer 传递给GridSearchCV

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

    【讨论】:

      猜你喜欢
      • 2018-04-19
      • 2018-07-14
      • 2015-10-17
      • 2018-11-05
      • 2021-01-09
      • 2020-03-07
      • 2019-05-27
      • 2018-10-22
      • 2019-03-03
      相关资源
      最近更新 更多