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)
来自https://en.wikipedia.org/wiki/Sensitivity_and_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:健康
来自https://en.wikipedia.org/wiki/False_positive_rate:
阳性率=假阳性/(假阳性+真阴性)
假阳性数:0 真阴性数:1
因此误报率 = 0 / 0 + 1 = 0
读取 roc_curve 的返回值(http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_curve.html#sklearn.metrics.roc_curve):
fpr : 数组,形状 = [>2]
增加误报率,使得元素 i 是分数 >= 阈值 [i] 的预测的误报率。
tpr : 数组,形状 = [>2]
增加真阳性率,使元素 i 是分数 >= 阈值 [i] 的预测的真阳性率。
阈值:数组,形状 = [n_thresholds]
降低用于计算 fpr 和 tpr 的决策函数的阈值。thresholds[0] 表示没有实例被预测,并且任意设置为 max(y_score) + 1。
这与我手动计算误报率的值有何不同?阈值是如何设置的?此处提供了有关阈值的一些模式信息:https ://datascience.stackexchange.com/questions/806/advantages-of-auc-vs-standard-accuracy但我对它如何适合此实现感到困惑?
