Description Usage Arguments Value Examples
View source: R/visualizations.R
Plot the Receiver Operating Characteristic curve for preds and labs.
1 2 |
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) |
No return value; file is saved to disk.
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.