mtcars is a data set of information on cars that is distributed with R. You can access it by typing its namehead(mtcars)
mpg, the efficiency of each car. The code below will separate the response from the predictors and scale the predictors to have 0 mean, unit variance. y_train = mtcars[, 1] x_train = mtcars[, -1] x_scaled = scale(x_train)
library(glmnet) fit = glmnet(x_scaled, y_train, alpha = 1)
cv.glmnet to find a good choice of penalty for the lasso modelfit_cv = cv.glmnet(x_scaled, y_train, alpha = 1)
fit_cv). How do these compare to standard linear regression?coef(fit_cv, s = "lambda.min")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.