
Discrimination: ROC, Precision-Recall, Gains, and Lift
Source:vignettes/discrimination.Rmd
discrimination.RmdDiscrimination evaluates how well a model separates positive
instances (events) from negative instances (non-events).
rtichoke groups discrimination visualizations into one
coherent conceptual family:
- Receiver Operating Characteristic (ROC) Curve: Sensitivity vs. 1 - Specificity.
- Precision-Recall (PR) Curve: Precision (PPV) vs. Recall (Sensitivity).
- Gains Curve: Cumulative percentage of positive outcomes vs. percentage of population targeted.
- Lift Curve: Factor by which model predictions improve detection over random targeting.
For methodological comparisons and statistical theory on when to prefer PR over ROC curves, see the rtichoke blog.
ROC Curves
ROC curves plot Sensitivity (True Positive Rate) against (False Positive Rate) across all probability thresholds.
library(rtichoke)
# Directly create an interactive ROC curve
create_roc_curve(
probs = list(
"Good Model" = example_dat$estimated_probabilities,
"Bad Model" = example_dat$bad_model,
"Random Guess" = example_dat$random_guess
),
reals = list(example_dat$outcome)
)Precision-Recall (PR) Curves
Precision-Recall curves are particularly informative in imbalanced datasets where the positive outcome prevalence is low.
create_precision_recall_curve(
probs = list(
"Good Model" = example_dat$estimated_probabilities,
"Bad Model" = example_dat$bad_model,
"Random Guess" = example_dat$random_guess
),
reals = list(example_dat$outcome)
)Gains Curves
Gains curves display the cumulative percentage of true positive cases captured as an increasingly larger fraction of the highest-risk population is targeted or screened.
create_gains_curve(
probs = list(
"Good Model" = example_dat$estimated_probabilities,
"Bad Model" = example_dat$bad_model
),
reals = list(example_dat$outcome)
)- Random Baseline: Diagonal line from to .
- Perfect Reference: Reaches true positives at a population percentage equal to the prevalence.
Lift Curves
Lift curves measure the ratio of model performance relative to a random selection baseline at any given population quantile.
create_lift_curve(
probs = list(
"Good Model" = example_dat$estimated_probabilities,
"Bad Model" = example_dat$bad_model
),
reals = list(example_dat$outcome)
)- Baseline Reference: Horizontal line at .
Prepared Data Workflow for Discrimination
If you plan to inspect multiple discrimination curves on the same models, prepare performance data once to avoid repeated calculations:
perf_data <- prepare_performance_data(
probs = list(
"Good Model" = example_dat$estimated_probabilities,
"Bad Model" = example_dat$bad_model
),
reals = list(example_dat$outcome)
)
# Render individual curves
plot_roc_curve(perf_data)
plot_precision_recall_curve(perf_data)
plot_gains_curve(perf_data)
plot_lift_curve(perf_data)