如何使用R的ROCR包只用一个类来处理标签(输出)?

时间:2015-02-19 16:10:40

标签: r machine-learning

我使用R的ROCR包测量模型的性能。我的代码的简单片段可以假设如下:

predic <- c(0.30, 0.59, 0.60, 0.71, 0.86)
label <- c(1,    1,    1,    1,     1)

pred <- ROCR::prediction(predic, label)

但不幸的是,听起来我不能仅使用一个类将ROCR用于标签(输出)而且我收到以下错误:

Error in ROCR::prediction(predic, label) : 
  Number of classes is not equal to 2.
ROCR currently supports only evaluation of binary classification tasks. 

有没有解决这个问题?

1 个答案:

答案 0 :(得分:0)

我认为你运气不好。甚至实例化预测&#39;宾语 直接引发错误......

cutoffs = sort(c(Inf,sort(predic,decreasing=TRUE)))
len = length(cutoffs)
tp <- apply(outer(sort(predic),cutoffs,`<`),2,sum)
fn=

new("prediction", 
    predictions = predic,
    labels = label,
    cutoffs = ,
    tp = tp, #cases
    fn = len-tp-1,#cases
    fp = rep.int(0,len),#controls
    tn = rep.int(0,len),#controls 
    n.pos = length(predic),
    n.neg = 0,
    n.pos.pred = tp,
    n.neg.pred = len-tp-1)


#> Error in initialize(value, ...) : argument is missing, with no default
#> Calls: new -> initialize -> initialize