How can I generate a plot of positive predictive value (PPV) vs various cut-off points for classifications?

后端 未结 1 928
情歌与酒
情歌与酒 2021-01-03 09:55

I have generated some scores to help predict whether or not something is yes (1) or no (0), let\'s say the data consists of:

scores = c(10:20)

response = c(         


        
1条回答
  •  走了就别回头了
    2021-01-03 10:21

    I will give an answer based around the pROC package*. It is possible to obtain similar results using the ROCR package as well.

    You want to use the coords function, which can compute several common statistics at some given thresholds. For instance, in order to get the PPV at all thresholds, you can do the following:

    library(pROC)
    r <- roc(response = response, predictor = scores)
    coordinates <- coords(r, x = "all", input = "threshold", ret = c("threshold", "ppv"))
    

    You can then plot those values:

    plot(t(coordinates))
    

    Replace "all" by the thresholds of interest:

     coordinates <- coords(r, x = c(13, 14, 15, 16, 17), input = "threshold", ret = c("threshold", "ppv"))
    

    * Disclaimer: I am the author of the pROC package.

    0 讨论(0)
提交回复
热议问题