简体   繁体   English

使用R的ROCR图

[英]ROCR Plot using R

I have a csv file (tab deliminated) which contains 2 columns which looks like such 我有一个csv文件(选项卡已删除),其中包含2列,看起来像这样

5   0
6   0
9   0
8   1
"+5000 lines similar lines"

I am attempting to create a ROC plot using ROCR. 我正在尝试使用ROCR创建ROC图。

This is what I have tried so far: 到目前为止,这是我尝试过的:

p<-read.csv(file="forROC.csv", head=TRUE, sep="\t")
pred<-prediction(p[1],p[2])

The second line gives me an error: Error in prediction(p[1], p[2]) : Number of classes is not equal to 2. ROCR currently supports only evaluation of binary classification tasks. 第二行给我一个错误: Error in prediction(p[1], p[2]) : Number of classes is not equal to 2. ROCR currently supports only evaluation of binary classification tasks.

I am not sure what the error is. 我不确定这是什么错误。 Is there something wrong with my CSV file? CSV文件有问题吗?

My guess is that your array indexing isn't setup properly. 我的猜测是您的数组索引设置不正确。 If you read in that CSV file, you should expect a data.frame (think matrix or 2D array, depending on your background) with two columns and 5,000+ rows. 如果您读取该CSV文件,则应该看到有两列和5,000+行的data.frame(根据您的背景,可以认为是矩阵或2D数组)。

So your current call to p[1] or p[2] aren't especially meaningful. 因此,您当前对p[1]p[2]调用并不是特别有意义。 You probably want to access the first and second column of that data.frame, which you can do using the syntax of p[,1] for the first column and p[,2] for the second. 您可能要访问该data.frame的第一和第二 ,您可以使用p[,1]的语法作为第一列,使用p[,2]的语法作为第二列。

The specific error you're encountering, however, is a complaint that the "truth" variable you're using isn't binary. 但是,您遇到的特定错误是您所使用的“真实”变量不是二进制的抱怨。 It seems that your file is setup to have an output of 1 and 0, so this error may go away once you properly access your array. 您的文件似乎设置为具有1和0的输出,因此一旦正确访问阵列,此错误可能就会消失。 But if you encounter this in the future, just be sure to binarize your truth data before you use it. 但是,如果将来遇到这种情况,请确保在使用真值数据之前将其二进制化。 For instance: 例如:

p[,2] <- p[,2] != 0

Would set the values to FALSE if it's a zero, and TRUE for each non-zero cell in the column. 如果将其设置为零,则将值设置为FALSE ;对于列中的每个非零单元格,则将其设置为TRUE

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

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