[英]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. 阈值有两个主要区别。
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
排列。
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_curve
, n_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: 步骤如下:
roc_curve
根据roc_curve
阈值计算与最低阈值相对应的精度和召回值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.