| wrap_glmnet | R Documentation |
Fits a 'glmnet' penalized regression model with a consistent interface. Supports regression and binary classification.
wrap_glmnet(x, y, ...)
## S3 method for class 'wrap_glmnet'
predict(object, newx, type = c("class", "prob"), s = NULL, ...)
## S3 method for class 'wrap_glmnet'
print(x, ...)
x |
A matrix or data.frame of features. |
y |
A factor or character vector for classification, numeric for regression. |
... |
Additional arguments passed to [glmnet::glmnet()]. Pass 'family = "binomial"' for binary classification. |
object |
A fitted 'wrap_glmnet' object. |
newx |
A matrix or data.frame of new observations. |
type |
'"class"' (default) for class labels, '"prob"' for a probability matrix. Ignored for regression. |
s |
Lambda value for prediction. Defaults to the midpoint of the lambda path. Pass 's = cv_fit$lambda.min' if using [glmnet::cv.glmnet()]. |
An object of class 'wrap_glmnet' with fields:
fit |
The fitted glmnet model. |
levels |
Class levels (NULL for regression). |
task |
"classification" or "regression". |
Multiclass ('family = "multinomial"') is not yet supported. For lambda selection, a specific 's' value can be passed to 'predict()'. By default the midpoint of the lambda path is used. For optimal lambda, use [glmnet::cv.glmnet()] externally and pass 's = fit$lambda.min'.
X <- iris[iris$Species != "virginica", 1:4]
y <- droplevels(iris[iris$Species != "virginica", "Species"])
mod <- wrap_glmnet(X, y, family = "binomial")
predict(mod, newx = X, type = "class")
predict(mod, newx = X, type = "prob")
X <- iris[iris$Species != "virginica", 1:4]
y <- droplevels(iris[iris$Species != "virginica", "Species"])
mod <- wrap_glmnet(X, y, family = "binomial")
predict(mod, newx = X, type = "class")
predict(mod, newx = X, type = "prob")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.