| MLElasticNet | R Documentation |
Fits the elastic-net coefficient path via coordinate descent
over a glmnet-style lambda grid (or an explicit grid). Reports coefficients
in the original predictor scale, intercepts, the deviance-ratio path, and
predictions for new data. The mixing parameter alpha interpolates
between lasso (alpha = 1) and ridge (alpha = 0).
MLElasticNet$new()Initialize the MLElasticNet object.
MLElasticNet$new(low_memory = FALSE, n_threads = NULL)
low_memoryLogical (default FALSE). FALSE: the
coordinate descent runs on a centered and standardized working copy of
X (one n x p matrix while fitting). TRUE: it runs on X itself
(an mmap_matrix is read in place, "readonly" suffices)
with no allocation of the size of X; same estimator and grid, the two
engines agree to rounding (about 1e-12 in the coefficients).
n_threadsInteger, the thread budget of the fit's matrix products
(NULL, the default: the library's default budget,
trex_get_num_threads(), initially 1).
MLElasticNet$fit()Fit the EN path over an auto-generated glmnet-style grid.
MLElasticNet$fit( X, y, alpha = 1, n_lambda = 100, lambda_min_ratio = -1, standardize = TRUE, intercept = TRUE, use_strong_rule = FALSE, max_iter = 1e+05, tol = 1e-07 )
XPredictor matrix (n x p), or an mmap_matrix (bound
zero-copy; "readonly" suffices, the fit does not modify X).
yResponse vector (n).
alphaMixing in [0, 1]: 1 = lasso, 0 = ridge (default 1).
n_lambdaGrid size (default 100).
lambda_min_ratioRatio lambda_min/lambda_max; negative (default) auto-selects glmnet's rule.
standardizeStandardize columns to unit SD (default TRUE).
interceptFit an unpenalized intercept (default TRUE).
use_strong_ruleEnable the sequential strong rule (default FALSE).
max_iterMax CD sweeps per lambda (default 100000).
tolConvergence tolerance (default 1e-7).
Invisibly returns self.
MLElasticNet$fit_grid()Fit the EN path at an explicit lambda grid (sorted descending internally); use to evaluate at exactly glmnet's sequence.
MLElasticNet$fit_grid( X, y, lambda_grid, alpha = 1, standardize = TRUE, intercept = TRUE, use_strong_rule = FALSE, max_iter = 1e+05, tol = 1e-07 )
XPredictor matrix (n x p), or an mmap_matrix (zero-copy).
yResponse vector (n).
lambda_gridExplicit lambda values (any order, > 0).
alphaMixing in [0, 1] (default 1).
standardizeStandardize columns to unit SD (default TRUE).
interceptFit an unpenalized intercept (default TRUE).
use_strong_ruleEnable the sequential strong rule (default FALSE).
max_iterMax CD sweeps per lambda (default 100000).
tolConvergence tolerance (default 1e-7).
Invisibly returns self.
MLElasticNet$get_coef()Coefficient path in original predictor scale (p x n_lambda).
MLElasticNet$get_coef()
Numeric matrix.
MLElasticNet$get_intercepts()Intercept per lambda (zero if intercept = FALSE).
MLElasticNet$get_intercepts()
Numeric vector.
MLElasticNet$get_lambdas()Lambda grid actually used (descending).
MLElasticNet$get_lambdas()
Numeric vector.
MLElasticNet$get_dev_ratio()Fraction of null deviance explained per lambda (glmnet %Dev).
MLElasticNet$get_dev_ratio()
Numeric vector.
MLElasticNet$converged()Whether every lambda reached the convergence tolerance.
MLElasticNet$converged()
Logical scalar.
MLElasticNet$n_nonconverged()Number of lambdas whose coordinate descent hit max_iter.
MLElasticNet$n_nonconverged()
Integer.
MLElasticNet$predict()Predictions per lambda for new data.
MLElasticNet$predict(X_new)
X_newPredictor matrix with the same number of columns as the
fit, or an mmap_matrix (zero-copy).
Numeric matrix (nrow(X_new) x n_lambda).
MLElasticNet$clone()The objects of this class are cloneable with this method.
MLElasticNet$clone(deep = FALSE)
deepWhether to make a deep clone.
H. Zou and T. Hastie, "Regularization and Variable Selection via the Elastic Net," J. R. Stat. Soc. Ser. B Stat. Methodol., vol. 67, no. 2, pp. 301-320, 2005.
J. Friedman, T. Hastie, and R. Tibshirani, "Regularization Paths for Generalized Linear Models via Coordinate Descent," J. Stat. Softw., vol. 33, no. 1, pp. 1-22, 2010, doi: 10.18637/jss.v033.i01.
Other ML methods:
MLElasticNetCV,
MLLpNormScaler,
MLPCA,
MLRidge,
MLRidgeCV,
MLSVD,
MLZScoreScaler,
ml_agglomerative_cluster(),
ml_cut_tree(),
ml_distance_metric,
ml_linkage_method
set.seed(1)
n <- 50; p <- 8
X <- matrix(rnorm(n * p), n, p)
y <- X[, 1] * 2 + X[, 3] - X[, 5] + rnorm(n)
en <- MLElasticNet$new()
en$fit(X, y, alpha = 1.0)
dim(en$get_coef()) # p x n_lambda
en$predict(X[1:5, ])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.