Ridge, Lasso & Elastic Net Regression with R | Boston Housing Data Example
{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) Load the libraries # https://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them list.of.packages <- c("caret", "glmnet", "mlbench","psych") new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] if(length(new.packages)) install.packages(new.packages, dependencies = T) # Libraries Needed library(caret) library(glmnet) library(mlbench) library(psych) # Data data("BostonHousing") data <- BostonHousing Data Partition set.seed(222) ind <- sample(2, nrow(data), replace = T, prob = c(0.7, 0.3)) train <- data[ind==1,] test <- data[ind==2,] Custom Control Parameters custom <- trainControl(method = "repeatedcv", number = 10, repeats = 5, verboseIter = T) Linear Model set