相关疑难解决方法(0)

通过sklearn.metrics.make_scorer将估算工具传递给自定义评分函数

我想制作一个涉及分类概率的自定义评分函数,如下所示:

def custom_score(y_true, y_pred_proba):
    error = ...
    return error

my_scorer = make_scorer(custom_score, needs_proba=True)

gs = GridSearchCV(estimator=KNeighborsClassifier(),
                  param_grid=[{'n_neighbors': [6]}],
                  cv=5,
                  scoring=my_scorer)
Run Code Online (Sandbox Code Playgroud)

有没有办法将GridSearch与给定的数据和参数一起传递给我的自定义评分函数?然后我可以使用解释概率estimator.classes_

例如:

def custom_score(y_true, y_pred_proba, clf):
    class_labels = clf.classes_
    error = ...
    return error
Run Code Online (Sandbox Code Playgroud)

python scikit-learn

6
推荐指数
1
解决办法
3269
查看次数

标签 统计

python ×1

scikit-learn ×1