Skip to content

Instantly share code, notes, and snippets.

@necronet
Created June 18, 2020 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save necronet/d48188717f3e89601ba8bc8e4d6ca1bc to your computer and use it in GitHub Desktop.
Save necronet/d48188717f3e89601ba8bc8e4d6ca1bc to your computer and use it in GitHub Desktop.
Quick gist to show lambda selection difference between explicit and heuristic
library(glmnet)
x_var <- data.matrix(mtcars[, c("hp", "wt", "drat")])
y_var <- mtcars[, "mpg"]
fit_lambda_specified <- cv.glmnet(x_var, y_var, alpha = 0, lambda = 10^seq(5, -5, by = -.1))
fit_lambda_automatic <- cv.glmnet(x_var, y_var, alpha = 0)
plot(fit_lambda_specified, xvar="lambda")
plot(fit_lambda_automatic, xvar="lambda")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment