Due: Tuesday 2020-03-24 at 11:59pm
In this lab we are going to practice cross validation. A few reminders:
lab-04-ridge-lasso-elastic-YOUR-GITHUB-HANDLE
. This repo contains a template you can build on to complete your assignment.In this lab we will work with two packages: tidyverse
which is a collection of packages for doing data analysis in a “tidy” way and tidymodels
for statistial modeling.
Now that the necessary packages are installed, you should be able to Knit your document and see the results.
If you’d like to run your code in the Console as well you’ll also need to load the packages there. To do so, run the following in the console.
Note that the packages are also loaded with the same commands in your R Markdown document.
Your email address is the address tied to your GitHub account and your name should be first and last name.
To confirm that the changes have been implemented, run the following
If you would like your git password cached for a week for this project, type the following in the Terminal:
Currently your project is called Untitled Project. Update the name of your project to be “Lab 04 - Ridge, Lasso, and Elastic Net”.
Before we introduce the data, let’s warm up with some simple exercises.
Open the R Markdown (Rmd) file in your project, change the author name to your name, and knit the document.
For this lab, we are using a data frame currently in music.csv
. This data frame includes 72 predictors that are components of audio files and one outcome, lat
, the latitude of where the music originated. We are trying to predict the location of the music’s origin using audio components of the music.
7
. Split the music
data into a training and test set with 50% of the data in the training and 50% in the testing. Call your training set music_train
and your testing set music_test
. Describe these data sets (how many observations, how many variables).## Parsed with column specification:
## cols(
## .default = col_double()
## )
## See spec(...) for full column specifications.
We are interested in predicting the latitude (lat
) of the music’s origin from all other variables. Fit a linear model using least squares on the training set. Report the test root mean squared error obtained.
Fit a ridge regression model on the training set with \(\lambda\) chosen using 10-fold cross valiation. Report the \(\lambda\) chosen and explain why. Report the test root mean squared error obtained using testing portion of the initially split data frame.
Fit a lasso model on the training set with \(\lambda\) chosen using cross valiation. Report the \(\lambda\) chosen and explain why. Report the test root mean squared error obtained using testing portion of the initially split data frame.
Fit an elastic net model on the training set with \(\lambda\) and \(\alpha\) chosen using cross valiation. Report the \(\lambda\) chosen and explain why. Report the test root mean squared error obtained using testing portion of the initially split data frame.
Comment on the results obtained. How accurately can we predict the latitude of where the music originated? Is there much difference among the test errors resulting from these four approaches?