Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For each exercise, provide the R code, the R output and comment both the codes and the results. For this exercise, the only extra packages

For each exercise, provide the R code, the R output and comment both the codes

and the results.

For this exercise, the only extra packages allowed are ISLR, leaps and glmnet.

a) Write the R function that takes two input arguments: a vector y and a matrix X. These

contain the data used for a supervised learning exercise where we are interested in

predicting y given X. The function must implement the four algorithms: Best subset

selection, forward stepwise selection, backward stepwise selection and the lasso. The

function must print out on the screen (in the R console) the variable names (along with

their coefficients) of the best model selected by each one of those 4 procedures. The best

model should be selected by BIC for the best subset selection, forward stepwise selection

and backward stepwise selection algorithms and by 10-fold cross-validation for the lasso.

b) Use the function on the following three datasets available in the package ISLR: Hitters,

Credit and Smarket. The output variable in each of these datasets are Salary, Balance

and Volume respectively. The input variables are selected from all the remaining variables

in each of the dataset.

c) Comment whether the forward stepwise selection, backward stepwise selection and lasso

algorithms were able to find the best model possible for each of those three datasets.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Finite Mathematics

Authors: Stefan Waner, Steven Costenoble

7th Edition

133751554X, 9781337515542

More Books

Students also viewed these Mathematics questions

Question

Peoples understanding of what is being said

Answered: 1 week ago

Question

The quality of the proposed ideas

Answered: 1 week ago