测试集上的接受者操作特征 (ROC)
receiver operating characteristic (ROC) on a test set
下图对我来说绝对有意义。
假设您有几个训练有素的二元分类器 A、B(B 并不比随机猜测等好多少......)和一个由 n 个测试样本组成的测试集来与所有这些分类器一起使用。由于针对所有 n 个样本计算 Precision 和 Recall,因此与分类器对应的那些点是有意义的。
现在有时人们谈论 ROC 曲线,我知道精确度表示为召回率的函数或简单地绘制 Precision(Recall)。
我不明白这种可变性从何而来,因为你有固定数量的测试样本。您是否只是选择测试集的一些子集并找到精度和召回率以便绘制它们以及许多离散值(或插值线)?
ROC曲线刚好显示"How much sensitivity you will obtain if you increase FPR by some amount"。 TPR 和 FPR 之间的权衡。可变性来自改变 classifier 的某些参数(对于下面的逻辑回归案例 - 它是阈值)。
例如,逻辑回归给出了对象属于正 class 的概率([0..1] 中的值),但这只是概率。这不是 class。所以在一般情况下,您必须指定概率阈值,高于该阈值您将 class 将对象确定为阳性。您可以学习逻辑回归,从中获得集合中每个对象的正 class 概率,然后您只需通过阈值化概率(在上一步计算) 使用此阈值,您将为每个对象获得 class 个标签,并根据此标签计算 TPR 和 FPR。因此,您将获得每个阈值的 TPR 和 FPR。您可以在图上标记它们,并最终在计算所有阈值的 (TPR,FPR) 对之后 - 通过它们画一条线。
同样对于线性二元 class 化器,您可以将此变化过程视为选择决策线和正(或负,如果需要)class 簇之间的距离的过程。如果您将决策线移到远离正 class 的地方 - 您将 class 将更多对象确定为正(因为您增加了正 class space),同时您FPR 增加了一些值(因为 space 的负数 class 减少了)。
ROC 曲线对于将其输出表示为 "score." 的二元 class 运算符定义明确。例如,分数可以是正 class,也可以是两种可能结果的概率分布之间的概率差(甚至是对数优势比)。
曲线是通过在不同级别设置此分数的决策阈值并在给定阈值的情况下测量真阳性和假阳性率而获得的。
在 Wikipedia's "Receiver Operating Characteristic" page 中有一个很好的这个过程的例子:
For example, imagine that the blood protein levels in diseased people and healthy people are normally distributed with means of 2 g/dL and 1 g/dL respectively. A medical test might measure the level of a certain protein in a blood sample and classify any number above a certain threshold as indicating disease. The experimenter can adjust the threshold (black vertical line in the figure), which will in turn change the false positive rate. Increasing the threshold would result in fewer false positives (and more false negatives), corresponding to a leftward movement on the curve. The actual shape of the curve is determined by how much overlap the two distributions have.
如果代码对您来说更清楚,这里是 scikit-learn 中的代码 computes an ROC curve given a set of predictions for each item in a dataset. The fundamental operation seems to be (direct link):
desc_score_indices = np.argsort(y_score, kind="mergesort")[::-1]
y_score = y_score[desc_score_indices]
y_true = y_true[desc_score_indices]
# accumulate the true positives with decreasing threshold
tps = y_true.cumsum()
fps = 1 + list(range(len(y_true))) - tps
return fps, tps, y_score
(我在其中省略了一堆代码,这些代码处理具有加权样本的(常见)情况以及 classifier 为多个样本提供接近相同的分数。)基本上是真实的标签按 classifier 分配给它们的分数降序排序,然后计算它们的累积和,给出真阳性率作为 classifier 分配的分数的函数。
下面是一个显示如何使用它的示例:http://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html
下图对我来说绝对有意义。
假设您有几个训练有素的二元分类器 A、B(B 并不比随机猜测等好多少......)和一个由 n 个测试样本组成的测试集来与所有这些分类器一起使用。由于针对所有 n 个样本计算 Precision 和 Recall,因此与分类器对应的那些点是有意义的。
现在有时人们谈论 ROC 曲线,我知道精确度表示为召回率的函数或简单地绘制 Precision(Recall)。
我不明白这种可变性从何而来,因为你有固定数量的测试样本。您是否只是选择测试集的一些子集并找到精度和召回率以便绘制它们以及许多离散值(或插值线)?
ROC曲线刚好显示"How much sensitivity you will obtain if you increase FPR by some amount"。 TPR 和 FPR 之间的权衡。可变性来自改变 classifier 的某些参数(对于下面的逻辑回归案例 - 它是阈值)。
例如,逻辑回归给出了对象属于正 class 的概率([0..1] 中的值),但这只是概率。这不是 class。所以在一般情况下,您必须指定概率阈值,高于该阈值您将 class 将对象确定为阳性。您可以学习逻辑回归,从中获得集合中每个对象的正 class 概率,然后您只需通过阈值化概率(在上一步计算) 使用此阈值,您将为每个对象获得 class 个标签,并根据此标签计算 TPR 和 FPR。因此,您将获得每个阈值的 TPR 和 FPR。您可以在图上标记它们,并最终在计算所有阈值的 (TPR,FPR) 对之后 - 通过它们画一条线。
同样对于线性二元 class 化器,您可以将此变化过程视为选择决策线和正(或负,如果需要)class 簇之间的距离的过程。如果您将决策线移到远离正 class 的地方 - 您将 class 将更多对象确定为正(因为您增加了正 class space),同时您FPR 增加了一些值(因为 space 的负数 class 减少了)。
ROC 曲线对于将其输出表示为 "score." 的二元 class 运算符定义明确。例如,分数可以是正 class,也可以是两种可能结果的概率分布之间的概率差(甚至是对数优势比)。
曲线是通过在不同级别设置此分数的决策阈值并在给定阈值的情况下测量真阳性和假阳性率而获得的。
在 Wikipedia's "Receiver Operating Characteristic" page 中有一个很好的这个过程的例子:
For example, imagine that the blood protein levels in diseased people and healthy people are normally distributed with means of 2 g/dL and 1 g/dL respectively. A medical test might measure the level of a certain protein in a blood sample and classify any number above a certain threshold as indicating disease. The experimenter can adjust the threshold (black vertical line in the figure), which will in turn change the false positive rate. Increasing the threshold would result in fewer false positives (and more false negatives), corresponding to a leftward movement on the curve. The actual shape of the curve is determined by how much overlap the two distributions have.
如果代码对您来说更清楚,这里是 scikit-learn 中的代码 computes an ROC curve given a set of predictions for each item in a dataset. The fundamental operation seems to be (direct link):
desc_score_indices = np.argsort(y_score, kind="mergesort")[::-1]
y_score = y_score[desc_score_indices]
y_true = y_true[desc_score_indices]
# accumulate the true positives with decreasing threshold
tps = y_true.cumsum()
fps = 1 + list(range(len(y_true))) - tps
return fps, tps, y_score
(我在其中省略了一堆代码,这些代码处理具有加权样本的(常见)情况以及 classifier 为多个样本提供接近相同的分数。)基本上是真实的标签按 classifier 分配给它们的分数降序排序,然后计算它们的累积和,给出真阳性率作为 classifier 分配的分数的函数。
下面是一个显示如何使用它的示例:http://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html