简体   繁体   English

如何在sklearn.metrics中为函数precision_recall_curve和roc_curve获得相同的阈值

[英]How to get the same thresholds values for both functions precision_recall_curve and roc_curve in sklearn.metrics

I need to make a table with the TPR and FPR values, as well as precision and recall. 我需要用TPR和FPR值以及精度和召回率制作一张表。 I am using the roc_curve and precision_recall_curve functions from sklearn.metrics package in python. 我正在使用python中sklearn.metrics包中的roc_curve和precision_recall_curve函数。 My problem is that every function give me a different vector for the thresholds, and I need only one, to merge the values as columns in a single table. 我的问题是,每个函数都为阈值提供了不同的向量,而我只需要一个函数就可以将值合并为单个表中的列。 Could anyone help me? 有人可以帮我吗?

Thanks in advance 提前致谢

The threshold values have two major differences. 阈值有两个主要区别。

  1. The orders are different. 订单是不同的。 roc_curve has thresholds in decreasing order, while precision_recall_curve has thresholds in increasing order. roc_curve阈值按降序排列,而precision_recall_curve阈值按roc_curve排列。

  2. The numbers are different. 数字不同。 In roc_curve , n_thresholds = len(np.unique(probas_pred)) , while in precision_recall_curve the number n_thresholds = len(np.unique(probas_pred)) - 1 . roc_curven_thresholds = len(np.unique(probas_pred)) ,而在precision_recall_curve ,数字n_thresholds = len(np.unique(probas_pred)) - 1 In the latter, the smallest threshold value from roc_curve is not included. 在后者中,不包含来自roc_curve的最小阈值。 In the same time, the last precision and recall values are 1. and 0. respectively with no corresponding threshold. 同时,最后的精度和召回值分别为1.和0。没有相应的阈值。 Therefore, the numbers of items for tpr, fpr, precision and recall are the same. 因此,tpr,fpr,精度和召回率的项目数相同。

So, back to your question, how to make a table to include tpr, fpr, precision and recall with corresponding thresholds? 因此,回到您的问题,如何制作一个表以包含具有相应阈值的tpr,fpr,精度和召回率? Here are the steps: 步骤如下:

  1. Discard the last precision and recall values 舍弃最后的精度并调用值
  2. Reverse the precision and recall values 反转精度和召回值
  3. Compute the precision and recall values corresponding to the lowest threshold value from the thresholds of roc_curve 根据roc_curve阈值计算与最低阈值相对应的精度和召回值
  4. Put all the values into the same table 将所有值放入同一表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sklearn roc_curve function 中定义的阈值数量是多少? - How number of thresholds is defined in sklearn roc_curve function? 绘制阈值(precision_recall 曲线)matplotlib/sklearn.metrics - Plotting Threshold (precision_recall curve) matplotlib/sklearn.metrics 不同阈值下的特异性(与 sklearn.metrics.precision_recall_curve 相同) - Specificity at different thresholds (in the same way as sklearn.metrics.precision_recall_curve) 使用不同分类器的 sklearn precision_recall_curve 函数 - Using sklearn precision_recall_curve function with different classifiers 在scikit的precision_recall_curve中,为什么阈值与召回和精确度有不同的维度? - In scikit's precision_recall_curve, why does thresholds have a different dimension from recall and precision? 模块“sklearn.metrics”没有属性“plot_roc_curve” - module 'sklearn.metrics' has no attribute 'plot_roc_curve' scikit 中 roc_curve 中的阈值学习 - thresholds in roc_curve in scikit learn sklearn.metrics.roc_curve 只显示 5 fprs、tprs、阈值 - sklearn.metrics.roc_curve only shows 5 fprs, tprs, thresholds sklearn.metrics.precision_recall_curve:为什么精度和重新调用返回的数组而不是单个值 - sklearn.metrics.precision_recall_curve: Why are the precision and recall returned arrays instead of single values precision_recall_curve 曲线仅返回单个值 - precision_recall_curve curve is returning only single value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM