python-2.7 - 如何在 python scikit-learn 中优化精确召回曲线而不是 AUC-ROC 曲线?

标签 python-2.7 machine-learning scikit-learn roc precision-recall

我正在按照我上一篇文章的建议提出后续问题 - Good ROC curve but poor precision-recall curve 。我仅使用 Python scikit-learn 的默认设置。看起来优化是在 AUC-ROC 上,但我更感兴趣的是优化 precision-recall。以下是我的代码。

# Get ROC 
y_score = classifierUsed2.decision_function(X_test)
false_positive_rate, true_positive_rate, thresholds = roc_curve(y_test, y_score)
roc_auc = auc(false_positive_rate, true_positive_rate)
print 'AUC-'+ethnicity_tar+'=',roc_auc
# Plotting
ax1.plot(false_positive_rate, true_positive_rate, c=color, label=('AUC-'+ethnicity_tar+'= %0.2f'%roc_auc))
ax1.plot([0,1],[0,1], color='lightgrey', linestyle='--')
ax1.legend(loc='lower right', prop={'size':8})

# Get P-R pairs
precision, recall, prThreshold = precision_recall_curve(y_test, y_score)
# Plotting
ax2.plot(recall, precision, c=color, label=ethnicity_tar)
ax2.legend(loc='upper right', prop={'size':8})

在哪里以及如何插入 python 代码来更改设置,以便优化精确记忆?

最佳答案

实际上您的问题中有两个问题:

  1. 如何评估单个数字的精确率-召回率曲线有多好?
  2. 如何构建模型来最大化这个数字?

我依次回答:

<强>1。精确率-召回率曲线质量的衡量标准是 average precision 。该平均精度等于未插值(即分段常数)精度召回曲线下的精确面积。

<强>2。为了最大化平均精度,您只能调整算法的超参数。如果您设置 scoring='average_ precision',则可以使用 GridSearchCV 来完成此操作。或者您可以手动或使用其他调整技术找到最佳超参数。

这通常不可能直接优化平均精度(在模型拟合期间),但也有一些异常(exception)。例如。 this article描述了一种最大化平均精度的 SVM。

关于python-2.7 - 如何在 python scikit-learn 中优化精确召回曲线而不是 AUC-ROC 曲线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35689623/

相关文章:

python - 如何在python中保存文件内容?

python - 使用Python请求库进行API GET请求

python - 导入错误 : No module named _ssl

python - 如何在 setup.py 中指定显式的 python 打包依赖项?

python - 如何在 tensorflow 中实现图像(二维数组)序列滑动窗口?

python - 一种管道可以同时适应文本和分类特征

python - 通过 MultiOutputRegressor 进行网格搜索?

python - CNN 训练准确度与 BatchNorm 停滞不前,在没有 BatchNorm 的情况下快速过度拟合

python - 二维数组中的 NaN 插值。人口稀少

python - 从 sklearn 中的高斯混合模型获取 PDF