开始使用免费开始使用

Plot an ROC curve

As you saw in the video, an ROC curve is a really useful shortcut for summarizing the performance of a classifier over all possible thresholds. This saves you a lot of tedious work computing class predictions for many different thresholds and examining the confusion matrix for each.

My favorite package for computing ROC curves is caTools, which contains a function called colAUC(). This function is very user-friendly and can actually calculate ROC curves for multiple predictors at once. In this case, you only need to calculate the ROC curve for one predictor, e.g.:

colAUC(predicted_probabilities, actual, plotROC = TRUE)

The function will return a score called AUC (more on that later) and the plotROC = TRUE argument will return the plot of the ROC curve for visual inspection.

本练习是课程的一部分

Machine Learning with caret in R

查看课程

练习说明

model, test, and train from the last exercise using the sonar data are loaded in your workspace.

  • Predict probabilities (i.e. type = "response") on the test set, then store the result as p.
  • Make an ROC curve using the predicted test set probabilities.

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Predict on test: p


# Make ROC curve
编辑并运行代码