scikit-learn - 如何在gridsearchcv中使用精确召回曲线?

标签 scikit-learn gridsearchcv

我正在尝试使用 sklearn gridsearchcv 进行超参数调整。我希望使用度量“precision_recall_curve 下的区域”。

gridsearchcv 类似于

>>> parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
>>> svc = svm.SVC()
>>> clf = GridSearchCV(svc, parameters, scoring='accuracy')
>>> clf.fit(iris.data, iris.target)

所以基本上我想要的是将字符串“accuracy”更改为 precision_recall_curve 下的区域。我应该如何定制它?

最佳答案

精确率-召回率曲线下的面积可以通过 average_precision_score 来估计。来自其documentation :

AP [Average Precision] summarizes a precision-recall curve as the weighted mean of precisions achieved at each threshold, with the increase in recall from the previous threshold used as the weight.

实际上,这是精确召回曲线下面积的近似值,并在 scikit-learn 中实现。有一个很棒的博客可用here总结了其背后的概念,并链接到 Wikipedia article其中指出:

[Average precision] is the area under the precision-recall curve.

可以通过指定 average_cision 作为评分方法来使用 average_ precision_score:

clf = GridSearchCV(svc, parameters, scoring='average_precision')

但是,请保持这一点重要note关于average_ precision_score请记住:

This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic.

关于scikit-learn - 如何在gridsearchcv中使用精确召回曲线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68567722/

相关文章:

scikit-learn - 多处理支持的并行循环不能嵌套在线程下

mysql - 对 mysql 中的列应用鲁棒缩放

python - 如何修复 OneClassSVM 和 GridSearchCV 的错误 "For multi-metric scoring"

python - 使用 GridsearchCV 提取管道中最佳模型的 MLPRegressor 属性 (n_iter_ )?

scikit-learn - 如何使用 GridSearchCV 预测每次迭代的 X_test?

python - 导入错误:无法为 sklearn 导入名称 'tree'

python-3.x - 如何获得离簇中心最近的N个数据点?

python - sklearn.model_selection.cross_val_score的score函数公式是什么?

python - 通过 GridSearchCV 测试的仅一类折叠

python - 如何访问 GridSearchCV 中的 ColumnTransformer 元素