prc {nestedcv} | R Documentation |
Build precision-recall curve
Description
Builds a precision-recall curve for a 'nestedcv' model using prediction()
and performance()
functions from the ROCR package and returns an object of
class 'prc' for plotting.
Usage
prc(...)
## Default S3 method:
prc(response, predictor, positive = 2, ...)
## S3 method for class 'data.frame'
prc(output, ...)
## S3 method for class 'nestcv.glmnet'
prc(object, ...)
## S3 method for class 'nestcv.train'
prc(object, ...)
## S3 method for class 'nestcv.SuperLearner'
prc(object, ...)
## S3 method for class 'outercv'
prc(object, ...)
## S3 method for class 'repeatcv'
prc(object, ...)
Arguments
... |
other arguments |
response |
binary factor vector of response of default order controls, cases. |
predictor |
numeric vector of probabilities |
positive |
Either an integer 1 or 2 for the level of response factor considered to be 'positive' or 'relevant', or a character value for that factor. |
output |
data.frame with columns |
object |
a 'nestcv.glmnet', 'nestcv.train', 'nestcv.SuperLearn', 'outercv' or 'repeatcv' S3 class results object. |
Value
An object of S3 class 'prc' containing the following fields:
recall |
vector of recall values |
precision |
vector of precision values |
auc |
area under precision-recall curve value using trapezoid method |
baseline |
baseline precision value |
Examples
library(mlbench)
data(Sonar)
y <- Sonar$Class
x <- Sonar[, -61]
fit1 <- nestcv.glmnet(y, x, family = "binomial", alphaSet = 1, cv.cores = 2)
fit1$prc <- prc(fit1) # calculate precision-recall curve
fit1$prc$auc # precision-recall AUC value
fit2 <- nestcv.train(y, x, method = "gbm", cv.cores = 2)
fit2$prc <- prc(fit2)
fit2$prc$auc
plot(fit1$prc, ylim = c(0, 1))
lines(fit2$prc, col = "red")
res <- nestcv.glmnet(y, x, family = "binomial", alphaSet = 1) |>
repeatcv(n = 4, rep.cores = 2)
res$prc <- prc(res) # precision-recall curve on repeated predictions
plot(res$prc)