machine-learning - 测试集上的接收器操作特性 (ROC)

标签 machine-learning statistics

下面的图片对我来说绝对有意义。 enter image description here

假设您有一些训练有素的二元分类器 A、B(B 并不比随机猜测等好多少......)和一个由 n 个测试样本组成的测试集,用于与所有这些分类器一起使用。由于精确率和召回率是针对所有 n 个样本计算的,因此与分类器相对应的那些点是有意义的。

现在有时人们谈论 ROC 曲线,我理解精度是表示为召回率的函数或简单地绘制精度(召回率)。

我不明白这种变异性从何而来,因为你有固定数量的测试样本。您是否只选择测试集的一些子集并找到精度和召回率,以便绘制它们并因此绘制许​​多离散值(或插值线)?

最佳答案

ROC 曲线对于二元分类器来说是明确定义的,它将其输出表示为“分数”。例如,分数可以是属于正类的概率,也可以是两种可能结果的概率分布之间的概率差(甚至对数优势比)。

通过在不同级别设置此分数的决策阈值并在给定阈值的情况下测量真阳性率和假阳性率来获得该曲线。

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给定数据集中每个项目的一组预测。基本操作似乎是( 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

(我在那里省略了一堆代码,这些代码处理具有加权样本的(常见)情况以及当分类器为多个样本提供几乎相同的分数时。)基本上,真实标签按降序排列分类器分配给它们的分数,然后计算它们的累积和,将真阳性率作为分类器分配的分数的函数给出。

下面是一个示例,展示了如何使用它:http://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html

关于machine-learning - 测试集上的接收器操作特性 (ROC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31994318/

相关文章:

java - 在一个 for 循环中计算整数数组的标准差,而无需提前知道平均值

mysql - 统计数据,例如来自大型记录集的网站显示

MySQL 使用 AVG 和 STD 条件选择排除异常值的结果

machine-learning - 在 PyTorch 中使用 WeightedRandomSampler

python - 如何使用 SVM 预测多类情感分析问题中的所有类?

java - 将 AWS SageMaker 机器学习模型转换为 Java 库

r - IQR和四分位数未按预期在R中生成

python - 我使用什么 scipy 统计测试来比较样本均值?

python - NLTK:语料库级 bleu 与句子级 BLEU 分数

machine-learning - Caffe 进行数据洗牌的方式