View source: R/learner_glmnet.R
| learner_glmnet_cv | R Documentation |
Constructs a learner class object for fitting entire lasso or
elastic-net regularization paths for various linear and non-linear regression
models with glmnet::cv.glmnet. Predictions are returned for the value of
lambda that gives minimum cvm. That is, glmnet::predict.cv.glmnet is
called with s = "lambda.min".
learner_glmnet_cv(
formula,
info = "glmnet::cv.glmnet",
family = gaussian(),
lambda = NULL,
alpha = 1,
nfolds = 10,
learner.args = NULL,
...
)
formula |
(formula) Formula specifying response and design matrix. |
info |
(character) Optional information to describe the instantiated learner object. |
family |
Either a character string representing
one of the built-in families, or else a |
lambda |
Optional user-supplied lambda sequence; default is
|
alpha |
The elasticnet mixing parameter, with
|
nfolds |
number of folds - default is 10. Although |
learner.args |
(list) Additional arguments to learner$new(). |
... |
Other arguments that can be passed to glmnet, for example |
learner object.
# continuous outcome
n <- 5e2
x1 <- rnorm(n, sd = 2)
x2 <- rnorm(n)
lp <- x1 + x2*x1 + cos(x1)
y <- rnorm(n, lp, sd = 2)
d0 <- data.frame(y, x1, x2)
lr <- learner_glmnet_cv(y ~ x1 + x2)
lr$estimate(d0, nfolds = 3)
lr$predict(data.frame(x1 = c(0, 1), x2 = 1))
# count outcome with different exposure time
w <- 50 + rexp(n, rate = 1 / 5)
y <- rpois(n, exp(0.5 * x1 - 1 * x2 + log(w)) * rgamma(n, 1 / 2, 1 / 2))
d0 <- data.frame(y, x1, x2, w)
lr <- learner_glmnet_cv(y ~ x1 + x2 + offset(log(w)), family = "poisson")
lr$estimate(d0, nfolds = 3)
lr$predict(data.frame(x1 = 1, x2 = 1, w = c(1, 5)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.