Learn R Programming

roclab (version 0.1.4)

plot.cv.roclearn: Visualize Cross-Validation results for linear models

Description

Produce a visualization of cross-validation results from a fitted cv.roclearn object. The plot shows the mean AUC across regularization parameters \(\lambda\), with error bars reflecting the cross-validation standard deviation. Optionally, the selected optimal \(\lambda\) is highlighted with a dashed line and marker.

Usage

# S3 method for cv.roclearn
plot(x, highlight = TRUE, ...)

Value

A ggplot2 object is returned and drawn to the current device.

Arguments

x

A cross-validation object of class "cv.roclearn".

highlight

Logical; if TRUE, mark the selected optimal \(\lambda\) with a vertical dashed line with a red point (default TRUE).

...

Additional arguments passed to underlying ggplot2 functions.

Details

This function is a method for the generic plot() function, designed specifically for cross-validation objects from cv.roclearn. The x-axis is displayed on a log scale for \(\lambda\), and the y-axis represents AUC values. Error bars show variability across folds.

Examples

Run this code
set.seed(123)

n <- 100
n_pos <- round(0.2 * n)
n_neg <- n - n_pos

X <- rbind(
  matrix(rnorm(2 * n_neg, mean = -1), ncol = 2),
  matrix(rnorm(2 * n_pos, mean =  1), ncol = 2)
)
y <- c(rep(-1, n_neg), rep(1, n_pos))

cvfit <- cv.roclearn(
  X, y,lambda.vec = exp(seq(log(0.01), log(5), length.out = 3)),
  approx=TRUE, nfolds = 2)

plot(cvfit)

Run the code above in your browser using DataLab