fracridge_cv | R Documentation |
Performs fractional ridge regression with cross-validation to select the optimal fraction.
fracridge_cv(
X,
y,
frac_grid = seq(0.1, 1, by = 0.1),
tol = 1e-10,
cv = 5,
scoring = "r2"
)
X |
A numeric matrix of shape |
y |
A numeric vector or matrix of shape |
frac_grid |
A numeric vector specifying the grid of fractions to consider for cross-validation.
Must be sorted in increasing order and be between 0 and 1. Default is |
tol |
A numeric value specifying the tolerance below which singular values are considered zero.
Must be positive. Default is |
cv |
An integer specifying the number of cross-validation folds, or an object to be used
as a cross-validation generator (e.g., |
scoring |
A character string or function to evaluate the predictions on the test set.
Default is |
This function performs fractional ridge regression across a grid of fractions and selects the fraction that maximizes the cross-validated performance metric (e.g., R-squared).
An object of class fracridge_cv
containing:
best_frac
The fraction that achieved the best cross-validated score.
coef
A numeric array of shape (p, b)
containing the estimated coefficients
for the best fraction and each target.
alpha
A numeric vector containing the regularization parameters associated with the best fraction for each target.
cv_results
A data frame containing cross-validation scores for each fraction.
## Not run:
# Generate random data
set.seed(1)
X <- matrix(rnorm(100 * 10), nrow = 100, ncol = 10)
y <- rnorm(100)
# Perform cross-validated fractional ridge regression
cv_result <- fracridge_cv(X, y, frac_grid = seq(0.1, 1.0, by = 0.1))
# Print the best fraction
print(cv_result$best_frac)
# Inspect coefficients
print(cv_result$coef)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.