2

I am trying to calculate accuracy using ROCR package in R but the result is different than what I expected:

Assume I have prediction of a model (p) and label (l) as following:

p <- c(0.61, 0.36, 0.43, 0.14, 0.38, 0.24, 0.97, 0.89, 0.78, 0.86)
l <- c(1,     1,    1,    0,    0,     1,    1,    1,    0,     1)

And I am calculating accuracy of this prediction using following commands:

library(ROCR)
pred <- prediction(p, l)
perf <- performance(pred, "acc")
max(perf@y.values[[1]])

but the result is .8 which according to accuracy formula (TP+TN)/(TN+TP+FN+FP) should be .6 I don't know why?

4

1 回答 1

3

当您使用max(perf@y.values[[1]])时,它会计算任何可能的截止值的最大准确度,以预测阳性结果。

在您的情况下,最佳阈值是p=0.2,在该阈值处您犯了 2 个错误(在预测概率为 0.38 和 0.78 的观察结果上),最大准确度为 0.8。

您可以使用访问 perf 对象的截止值perf@x.values[[1]]

于 2013-12-14T20:47:52.407 回答