Get startedGet started for free

Plot ROC curves

You saw again that the boosted tree yields the highest AUC. Numbers are fine, but pictures are better! Why not visualize these results?

You are going to illustrate model performance by plotting all ROC curves on one common plot. As the AUC is literally the area under these ROC curves, the boosted model should have the largest area under its ROC curve and be the one in the upper left corner of the plot.

The predictions tibble, preds_combined, is still loaded.

This exercise is part of the course

Machine Learning with Tree-Based Models in R

View Course

Exercise instructions

  • Reshape the preds_combined tibble so that all columns that start with "preds_" are rows instead of columns. Convert the names to a "model" column and the values to a column called "predictions".
  • Group the results by model.
  • Calculate the ROC values for all cutoffs.
  • Produce a graphical plot of the curves.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Reshape the predictions into long format
predictions_long <- tidyr::pivot_longer(___,
                                        cols = starts_with("___"),
                                        names_to = "___",
                                        values_to = "___")

predictions_long %>% 
  # Group by model
  ___(___) %>% 
  # Calculate values for every cutoff
  ___(truth = ___, 
      estimate = ___) %>%
  # Create a plot from the calculated data
  ___()
Edit and Run Code