import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc , roc_auc_score
import numpy as np
correct_classification = np.array([0,1])
predicted_classification = np.array([1,1])
false_positive_rate, true_positive_rate, tresholds = roc_curve(correct_classification, predicted_classification)
print(false_positive_rate)
print(true_positive_rate)来自specificity:
True positive: Sick people correctly identified as sick
False positive: Healthy people incorrectly identified as sick
True negative: Healthy people correctly identified as healthy
False negative: Sick people incorrectly identified as healthy我使用这些值0:病态,1:健康
来自rate:
荧光阳性率=假阳性/(假阳性+真阴性)
假阳性数:0真实阴性数:1
因此,假阳性率=0/0+1=0
读取roc_curve (curve)的返回值:
fpr :数组,形状= >2 增加假阳性率,例如元素I,是用分数>=阈值预测的假阳性率。 tpr :数组,shape = >2 增加真实阳性率这样的元素I是真实阳性预测的真实阳性率与分数>=阈值。 阈值:数组,shape = n_thresholds 降低用于计算fpr和tpr的决策函数的阈值。阈值表示没有被预测的实例,并且被任意设置为max(y_score) + 1。
这与我手工计算的假阳性率有何不同?阈值是如何设定的?这里提供了一些关于阈值的模式信息:https://datascience.stackexchange.com/questions/806/advantages-of-auc-vs-standard-accuracy,但我对它如何与此实现相适应感到困惑?
发布于 2018-09-04 16:43:11
首先,维基百科正在考虑sick=1。
真正的积极:病人被正确地认定为病人。
第二,每个模型都有基于正类概率的阈值(一般为0.5)。
因此,如果阈值为0.1,所有概率大于0.1的样本将被归类为阳性。预测样本的概率是固定的,阈值也会发生变化。
在roc_curve中,scikit-learn从以下几个方面提高阈值:
0 (or minimum value where all the predictions are positive) 至
1 (Or the last point where all predictions become negative).中间点是根据预测从正向负的变化来决定的。
示例:
Sample 1 0.2
Sample 2 0.3
Sample 3 0.6
Sample 4 0.7
Sample 5 0.8这里的最低概率是0.2,所以任何意义的最小阈值都是0.2。现在,当我们不断地增加阈值时,由于这个例子中的点非常少,每个概率都会改变阈值(并且等于该概率,因为这是正负变化的点)。
Negative Positive
<0.2 0 5
Threshold1 >=0.2 1 4
Threshold2 >=0.3 2 3
Threshold3 >=0.6 3 2
Threshold4 >=0.7 4 1
Threshold5 >=0.8 5 0发布于 2018-09-04 15:02:37

在上面的演示中,阈值是橙色条。00类的分布为红色(分类器的输出),第1类的分布为蓝色(同样,分类器输出的proba分布)。它适用于某一类或另一类的概率:如果一个样本有0.34,0.66的输出,那么即使proba为0.66,1级的阈值0.25也会使他进入1级。
你不是在课的曲线上工作,而是在上课的前提下工作。
我希望它能回答这个问题(如果没有,如果需要的话,我会更精确)。
https://stackoverflow.com/questions/52167659
复制相似问题