MLRidgeCV: Ridge Regression with Cross-Validation

MLRidgeCVR Documentation

Ridge Regression with Cross-Validation

Description

Performs explicit K-Fold cross-validation for Ridge Regression model selection.

Methods

Public methods


MLRidgeCV$new()

Initialize the MLRidgeCV object.

Usage
MLRidgeCV$new(low_memory = FALSE, n_threads = NULL)
Arguments
low_memory

Logical (default FALSE). FALSE: each fold gathers and standardizes its training rows and takes a thin SVD (about three to four copies of X in flight). TRUE: the dual (kernel) form — n x n kernels accumulated from column blocks of X read in place (an mmap_matrix included, "readonly" suffices), no p-dimensional coefficients; same estimator, grid and rank rule, agreement to numerical precision; memory O(n^2) instead of O(n p), the route for p >> n.

n_threads

Integer, the thread budget of the fit's matrix products (NULL, the default: the library's default budget, trex_get_num_threads(), initially 1).


MLRidgeCV$fit()

Fit the CV model.

Usage
MLRidgeCV$fit(
  X,
  y,
  n_folds = 10,
  n_lambda = 100,
  lambda_ratio = 1000,
  seed = 0
)
Arguments
X

Predictor matrix, or an mmap_matrix created by mem_matrix / mem_matrix_from (bound zero-copy; "readonly" mode suffices since the fit does not modify X).

y

Response vector.

n_folds

Number of folds (default 10).

n_lambda

Number of lambdas in the path (default 100).

lambda_ratio

Ratio of max to min lambda (default 1000).

seed

Random seed for CV splits (default 0).

Returns

Value.


MLRidgeCV$cv_min()

Get lambda that minimizes CV error.

Usage
MLRidgeCV$cv_min()
Returns

Value.


MLRidgeCV$cv_1se()

Get 1SE rule lambda.

Usage
MLRidgeCV$cv_1se()
Returns

Value.


MLRidgeCV$index_min()

Get index of minimum CV error.

Usage
MLRidgeCV$index_min()
Returns

Value.


MLRidgeCV$index_1se()

Get index of 1SE rule lambda.

Usage
MLRidgeCV$index_1se()
Returns

Value.


MLRidgeCV$get_lambdas()

Get the sequence of lambdas used.

Usage
MLRidgeCV$get_lambdas()
Returns

Value.


MLRidgeCV$get_cv_errors()

Get the CV mean squared errors for each lambda.

Usage
MLRidgeCV$get_cv_errors()
Returns

Value.


MLRidgeCV$get_cv_std()

Get the standard error of the CV errors.

Usage
MLRidgeCV$get_cv_std()
Returns

Value.


MLRidgeCV$interpolates()

Whether the smallest training fold has p >= n_train, so the lambda -> 0 end of the grid tends to the minimum-norm interpolator instead of an ordinary least-squares fit. The curve still has a genuine interior minimum in that regime; together with selection_at_grid_edge() it tells whether cv_min() is a real minimum or the grid running out.

Usage
MLRidgeCV$interpolates()
Returns

Logical.


MLRidgeCV$selection_at_grid_edge()

Whether cv_min() or cv_1se() landed on the first or the last grid point. The pick is then the grid boundary, not an optimum, and lambda_ratio or n_lambda need widening.

Usage
MLRidgeCV$selection_at_grid_edge()
Returns

Logical.


MLRidgeCV$clone()

The objects of this class are cloneable with this method.

Usage
MLRidgeCV$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

References

A. E. Hoerl and R. W. Kennard, "Ridge Regression: Biased Estimation for Nonorthogonal Problems," Technometrics, vol. 42, no. 1, pp. 80-86, 2000 (Reprint of the 1970 article in the Special 40th Anniversary Issue).

G. Guennebaud, B. Jacob et al., Eigen v3, https://libeigen.gitlab.io/, 2010.

See Also

Other ML methods: MLElasticNet, MLElasticNetCV, MLLpNormScaler, MLPCA, MLRidge, MLSVD, MLZScoreScaler, ml_agglomerative_cluster(), ml_cut_tree(), ml_distance_metric, ml_linkage_method

Examples

set.seed(1)
X <- matrix(rnorm(50 * 5), 50, 5)
y <- X[, 1] * 2 + rnorm(50)
cv <- MLRidgeCV$new()
cv$fit(X, y, n_folds = 5)
cv$cv_min()
cv$selection_at_grid_edge()   # FALSE: the picks are interior grid points


TRexSelector documentation built on Nov. 20, 2026, 5:09 p.m.