在R中计算精度,召回率和F1分数的简便方法 [英] Easy way of counting precision, recall and F1-score in R

查看:804
本文介绍了在R中计算精度,召回率和F1分数的简便方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R中使用 rpart 分类器。问题是-我想在测试数据上测试经过训练的分类器。很好-我可以使用 predict.rpart 函数。

I am using an rpart classifier in R. The question is - I would want to test the trained classifier on a test data. This is fine - I can use the predict.rpart function.

但是我也想计算精度,回想一下和F1分数。

But I also want to calculate precision, recall and F1 score.

我的问题是-我是否必须为自己编写函数,或者R或CRAN库中是否有为此编写的函数?

My question is - do I have to write functions for those myself, or is there any function in R or any of CRAN libraries for that?

推荐答案

ROCR 库将计算所有这些以及更多内容(另请参见 http:// rocr。 bioinf.mpi-sb.mpg.de ):

The ROCR library calculates all these and more (see also http://rocr.bioinf.mpi-sb.mpg.de):

library (ROCR);
...

y <- ... # logical array of positive / negative cases
predictions <- ... # array of predictions

pred <- prediction(predictions, y);

# Recall-Precision curve             
RP.perf <- performance(pred, "prec", "rec");

plot (RP.perf);

# ROC curve
ROC.perf <- performance(pred, "tpr", "fpr");
plot (ROC.perf);

# ROC area under the curve
auc.tmp <- performance(pred,"auc");
auc <- as.numeric(auc.tmp@y.values)

...

这篇关于在R中计算精度,召回率和F1分数的简便方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆