简体   繁体   English

如何使用AUC绘制ROC曲线?

[英]How can I plot a ROC curve with AUC?

I am trying to classify two different cases. 我正在尝试对两种不同的情况进行分类。 Therefore I built decision trees, the confusion matrix and calculated the accuracy, sensitivity and the specificitvy. 因此,我建立了决策树,混淆矩阵并计算了准确性,敏感性和特异性。 I ran my program 100 times, so I have 100 accuracy, sensitivity and specificitvy values. 我将程序运行了100次,因此我有100个准确性,灵敏度和特异度值。

What I want to do now is to plot the ROC curve with the AUC. 现在要做的是用AUC绘制ROC曲线。 I did some researches and all these examples were discussing probabilities and I don't know what exactly these are. 我做了一些研究,所有这些例子都在讨论概率,但我不知道它们到底是什么。

So can anyone help me to plot this? 有人可以帮我画图吗? I don't know which part of my code I should present, so please feel free to ask for it. 我不知道应该在代码的哪一部分进行演示,因此请随时提出要求。

You could use a package like pROC, which may be easier than creating it yourself. 您可以使用像pROC这样的软件包,它比您自己创建的包更容易。 You use the roc() function to create a roc object and then plot() to plot the object and create the ROC curve. 您可以使用roc()函数创建roc对象,然后使用plot()绘制对象并创建ROC曲线。

Also, it doesn't sound like you are going about this in the right way. 此外,听起来好像您没有以正确的方式进行操作。 The ROC curve is calculated from sensitivity and specificity values taken at different cut points across the range of possible probabilities from you model ie at cut points between 0 and 1. You don't need to create 100 sets of model predictions, just one model will suffice. ROC曲线是根据模型中可能出现的概率范围内不同切点处(即0到1之间的切点)处获得的敏感性和特异性值计算得出的。您无需创建100组模型预测,只需一个模型即可满足。

Try something like this, where y is your response variable and p is the vector of probability values output by your model: 尝试这样的方法,其中y是您的响应变量,p是模型输出的概率值的向量:

plot(roc(y, p)), print.auc = TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM