Guest User

Untitled

a guest
Mar 18th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. fast <- function(input, truth){
  2.  
  3. input_clust <- outer(input,input,"==")
  4. truth_clust <- outer(truth,truth,"==")
  5.  
  6. tp <- (input_clust & truth_clust)
  7. fp <- input_clust & !truth_clust
  8. tn <- !input_clust & !truth_clust
  9. fn <- !input_clust & truth_clust
  10.  
  11. tp <- sum(tp & upper.tri(tp))
  12. fp <- sum(fp & upper.tri(fp))
  13. tn <- sum(tn & upper.tri(tn))
  14. fn <- sum(fn & upper.tri(fn))
  15.  
  16. precision = 0
  17. recall = 0
  18. f_1 = 0
  19.  
  20. if((tp>0)){
  21. precision = tp/(tp+fp)
  22. }
  23. if((tp>0)){
  24. recall = tp/(tp+fn)
  25. }
  26. if((precision > 0 & recall > 0)){
  27. f_1=(2*precision*recall)/(precision+recall)
  28. }
  29.  
  30. return (c(precision,recall,f_1))
  31. }
Add Comment
Please, Sign In to add comment