roc_plot: Plot the Receiver Operating Characteristic curve for preds...

Description Usage Arguments Value Examples

View source: R/visualizations.R

Description

Plot the Receiver Operating Characteristic curve for preds and labs.

Usage

1
2
roc_plot(preds, labs, plot_type = NULL, show_diag = FALSE,
  fout = NULL)

Arguments

preds

vector of predictions

labs

vector of true class labels

plot_type

if set to "majority" or "minority", coloring is set to match plots generated by slice_plot (blue for majority class, red for minority); if NULL then neutral coloring is used

show_diag

boolean indicator for whether a diagonal line indicating the random chance ROC curve should be plotted

fout

path to an output file (png)

Value

No return value; file is saved to disk.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
 
# 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 roc_plot() to the labels and predictions 
# (note that this writes a file to fout):
roc_plot(testdata$pred, testdata$returned, plot_type = "majority", 
    show_diag=TRUE, fout="roc.png")

jpgard/abroca documentation built on May 25, 2019, 11:31 p.m.