我们如何计算 R 中的平均精度分数?有没有简单的方法?
我计算如下。我不知道这是否完全正确。。
pr = prediction(preds, labs)
pf = performance(pr, "prec", "rec")
# plot(pf)
pf@x.name
[1] "Recall"
pf@y.name
[1] "Precision"
rec = pf@x.values[[1]]
prec = pf@y.values[[1]]
idxall = NULL
for(i in 1:10){
i = i/10
# find closest values in recall to the values 0, 0.1, 0.2, ... ,1.0
idx = which(abs(rec-i)==min(abs(rec-i)))
# there are more than one value return, choose the value in the middle
idx = idx[ceiling(length(idx)/2)]
idxall = c(idxall, idx)
}
prec.mean = mean(prec[idxall])