Fig2.5 | R Documentation |
Reproduces Figure 2.5 from the book; if you specify any options, your results may look different.
Fig2.5(cv = TRUE, mar = rep(5, 4))
cv |
Carry out cross-validation? Default: true |
mar |
Margins, passed to |
Fig2.5()
# default glmnet plot
attach_data(pollution)
fit <- glmnet(std(X), y) # Standardize design matrix
plot(fit, label=TRUE)
# Nonzero coefficients at CV-selected lambda
cvfit <- cv.glmnet(X, y, nfolds=length(y))
colnames(X)[unlist(predict(cvfit, type="nonzero"))]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.