Description Usage Arguments Value See Also Examples
View source: R/roc_auc_utils.R
Compute Area Under the Receiver Operating Characteristic Curve (AUC)
1 | compute_auc(preds, labs)
|
preds |
vector of predicted probabilities (numeric) |
labs |
vector of true class labels (numeric) |
value of Area Under the Receiver Operating Characteristic Curve (AUC) (numeric)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # First, we load data, train a model, and generate predictions to evaluate.
data("recidivism")
recidivism$returned = as.factor(recidivism$Return.Status != "Not Returned")
in_train = caret::createDataPartition(recidivism$returned,
p = 0.75, list = FALSE)
traindata = recidivism[in_train,c("Release.Year", "County.of.Indictment",
"Gender", "Age.at.Release", "returned")]
testdata = recidivism[-in_train,c("Release.Year", "County.of.Indictment",
"Gender", "Age.at.Release", "returned")]
lr = glm(returned ~ ., data=traindata, family="binomial")
testdata$pred = predict(lr, testdata, type = "response")
# Now, we apply compute_auc() to the labels and predictions:
compute_auc(testdata$pred, testdata$returned)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.