Last active
April 28, 2017 22:22
-
-
Save alexpghayes/dbe636d510e6acfa50bf5741289ea7cc to your computer and use it in GitHub Desktop.
glmnet factor example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(glmnet) | |
x <- model.matrix(mpg ~ factor(cyl) + factor(gear) + wt * factor(gear), mtcars) | |
y <- mtcars$mpg | |
x | |
fit <- cv.glmnet(x, y, alpha = 1) # lasso when alpha = 1, ridge when alpha = 0 | |
coef(fit, s = fit$lambda.min) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment