Home > Software engineering >  How to create a precision-recall curve in R from binary data?
How to create a precision-recall curve in R from binary data?

Time:03-05

I'd like to calculate precision and recall and create a precision-recall plot in R from a binary dataset (did an event occur/not occur). My data is set out similar to the below example.

truth <- rbinom(200, 1, 0.9)
pred_1 <- rbinom(200, 1, 0.8)
pred_2 <- rbinom(200, 1, 0.7)

dat <- data.frame(truth, pred_1, pred_2)

head(dat)
#>   truth pred_1 pred_2
#> 1     1      1      1
#> 2     1      1      1
#> 3     1      1      0
#> 4     0      1      1
#> 5     1      0      1
#> 6     1      1      1

I essentially aim to assess the precision and recall of pred_1 and pred_2 to determine an "event" (identified as 1) compared to truth (criterion). I know there are some packages/functions in R that can visualise precision/recall, but I'm not sure of the best approach for this example. I came across the pr_curve function from the yardstick package, but I'm not sure how to apply the enter image description here

  •  Tags:  
  • r
  • Related