本文主要是介绍R中快速绘制PR曲线并计算AUPR-modEvA包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言:
绘制ROC曲线的R包有很多,例如pROC、ROCR等,并可以获得AUC,有的顺便可以绘制PR曲线,但不能获得AUPR。最近需要获取AUPR,但查询网上几乎没有关于AUPR的,这里查找到一个简单的R包-modEvA,写下使用的简单案例。
术语:
PR曲线:precision-recall curve,以recall作为横坐标轴,precision作为纵坐标轴
AUPR:Area under the precision-recall curve,PR曲线下的面积
参考:
Barbosa A.M., Real R., Muñoz A.R. & Brown J.A. (2013) New measures for assessing model equilibrium and prediction mismatch in species distribution models. Diversity and Distributions 19: 1333-1338 (DOI: 10.1111/ddi.12100)
https://cran.r-project.org/web/packages/modEvA/modEvA.pdf
http://modeva.r-forge.r-project.org/
安装:
modEvA已经存放在CRAN中,所以可以在Rstudio中直接安装:
install.packages('modEvA')
安装过后加载:
library(modEvA)
使用案例:
函数:
AUC(model = NULL, obs = NULL, pred = NULL, simplif = FALSE, interval = 0.01, FPR.limits = c(0, 1), curve = "ROC", method = "rank", plot = TRUE, diag = TRUE, diag.col = "grey", diag.lty = 1, curve.col = "black", curve.lty = 1, curve.lwd = 2, plot.values = TRUE, plot.digits = 3, plot.preds = FALSE, grid = FALSE, xlab = "auto", ylab = "auto", ...)
详细的参数介绍见官方文档
obs:标签向量
pred:预测的结果向量
curve ='ROC' 或者PR,表示ROC曲线还是PR曲线
simplify:等于TRUE时,函数只返回AUC或AUPR
数据:
调用:
auc=AUC(obs=score$link,pred=score$score,curve = "ROC", simplif=TRUE, main = "ROC curve")
aupr=AUC(obs=score$link,pred=score$score,curve = "PR", simplif=TRUE, main = "PR curve")
结果:
这篇关于R中快速绘制PR曲线并计算AUPR-modEvA包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!