I haven't used R in a while, so maybe I'm just not used to it yet, but.. I have a table in R with two colums, the first one has predicted values (a value can be either 0 or 1), the second one has the actual values (also 0 or 1). I need to find recall, precision and f-measures, but cannot find a good function for it in R. (I also read about ROCR, but all I could do was creating some plots, but I really don't need plots, I need the numbers).
Is there any good functions for finding precision, recall and f-measure in R? Are there any different ways to do it?
Precision quantifies the number of positive class predictions that actually belong to the positive class. Recall quantifies the number of positive class predictions made out of all positive examples in the dataset. F-Measure provides a single score that balances both the concerns of precision and recall in one number.
The F1 Score is the 2*((precision*recall)/(precision+recall)). It is also called the F Score or the F Measure. Put another way, the F1 score conveys the balance between the precision and the recall. The F1 for the All No Recurrence model is 2*((0*0)/0+0) or 0.
measurePrecisionRecall <- function(actual_labels, predict){
conMatrix = table(actual_labels, predict)
precision <- conMatrix['0','0'] / ifelse(sum(conMatrix[,'0'])== 0, 1, sum(conMatrix[,'0']))
recall <- conMatrix['0','0'] / ifelse(sum(conMatrix['0',])== 0, 1, sum(conMatrix['0',]))
fmeasure <- 2 * precision * recall / ifelse(precision + recall == 0, 1, precision + recall)
cat('precision: ')
cat(precision * 100)
cat('%')
cat('\n')
cat('recall: ')
cat(recall * 100)
cat('%')
cat('\n')
cat('f-measure: ')
cat(fmeasure * 100)
cat('%')
cat('\n')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With