Description Usage Arguments Value See Also Examples
View source: R/roc_auc_utils.R
Use interpolation to make approximate the Receiver Operating Characteristic (ROC) curve along n_grid equally-spaced values.
1 | interpolate_roc_fun(perf_in, n_grid = 10000)
|
perf_in |
ROCR::performance object computed via |
n_grid |
number of approximation points to use (default value of 10000 more than adequate for most applications) (numeric) |
returns a list with components x and y, containing n coordinates which interpolate the given data points according to the method (and rule) desired.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # 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_roc() to the labels and predictions,
# which generates a ROCR::performance object:
roc <- compute_roc(testdata$pred, testdata$returned)
# Interpolate_roc_fun is applied to this object:
roc_approx <- interpolate_roc_fun(roc)
# You can also increase the quality of the approximation.
# Increasing the approximation rarely makes a substantial difference,
# but is available as a convenience for massive datasets or when
# precision is critical.
roc_approx_finegrain <- interpolate_roc_fun(roc, n_grid = 1000000)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.