r - 没有足够的明确预测来计算 roc 下的面积

标签 r roc auc

我正在使用 auc(roc(predictions, labels)) 计算 AUC,其中 labels1 的数值向量> (x15) 和 0 (x500),而 predictions 是一个数值向量,其概率源自 glm [二项式]。它应该非常简单,但是 auc(roc(predictions, labels)) 给出错误,指出“没有足够的不同预测来计算 ROC 曲线下的面积”。我一定是在做一些愚蠢的事情,但我无法发现是什么。你可以吗?

代码是

library(AUC)
#read the data, that come from a previous process of a species distribution modelling
prob<-read.csv("prob.csv")
labels<-read.csv("labels.csv")
#prob is
#labels is

roc(prob,labels)

#Gives the error (that I'm NOT interest in)
Error in `[.data.frame`(predictions, pred.order) : undefined columns selected
In addition: Warning messages:
1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
2: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
3: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'

#I change the format to numeric vector
prob<-as.numeric(prob[,2])
labels<-as.numeric(labels[,2])
#Verify it is a vector numeric
class(prob)
[1] "numeric"
class(labels)
[1] "numeric"

#call the roc functoin
roc(prob,labels)

Error in roc(modbrapred, pbbra) : # THIS is the error I0m interested in
  Not enough distinct predictions to compute area under the ROC curve.
In addition: Warning messages:
1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
2: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'
3: In is.na(e2) : is.na() applied to non-(list or vector) of type 'NULL'    

Data is as follows

labels.csv
"","x"
"1",1
"2",1
"3",1
"4",1
"5",1
"6",1
...
"164",1
"165",1
"166",0
"167",0
"168",0
"169",0
"170",0
"171",0
"172",0 
...
"665",0

prob.csv
"","x"
"1",0.977465874525236
"2",0.989692657762578
"3",0.989692657762578
"4",0.988038430564019
"5",0.443188602491041
"6",0.409732585195485
...
"164",0.988607910625475
"165",0.986296936078692
"166",7.13529696560611e-05
"167",0.000419255989134081
"168",0.00295825183558019
"169",0.00182941235784709
"170",4.85601026999172e-09
"171",0.000953106471289961
"172",1.70252014430306e-05
...
"665",8.13413358866349e-08

最佳答案

问题是我的“标签”是一个数字向量,但我需要一个因子。于是我就转型了

labels <- factor(labels)

大鹏鸟按其应有的方式工作

感谢您投入的时间

关于r - 没有足够的明确预测来计算 roc 下的面积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25608204/

相关文章:

r - 使用neuralnet和ROCR包绘制神经网络曲线

r - 使用 pROC 的 PPV 和 NPV CI

python - 如何手动计算ROC的AUC?

r - S3 泛型/方法一致性 - 如何根据所选类型进行调度?

r - R中ggplot2 barplot中的可变宽度条

r - 如何在 pROC 中绘制具有置信区间的多条 roc 曲线?

r - 为 R 中的逻辑回归模型绘制多条 ROC 曲线

keras - 在 Keras 中加载模型

r - 将 R 中不太常见的因子级别合并到 "Others"

r - 如何区分R中的元素和长度为1的向量?