Question: This part of the assignment involves building generalized linear regression models to answer a number of questions. We will use the Carseats dataset that is

This part of the assignment involves building generalized linear regression models to answer a number of questions. We will use the Carseats dataset that is part of the ISLR package (you need to install and load the library). We may also need the following packages: caret, dplyr and glmnet Lets start by loading these libraries: library(ISLR) ## Warning: package 'ISLR' was built under R version 4.0.3 library(dplyr) ## Warning: package 'dplyr' was built under R version 4.0.2

## Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame' ## when loading 'dplyr' ## ## Attaching package: 'dplyr' ## The following objects are masked from 'package:stats': ## ## filter, lag ## The following objects are masked from 'package:base': ## ## intersect, setdiff, setequal, union library(glmnet) ## Warning: package 'glmnet' was built under R version 4.0.2 ## Loading required package: Matrix ## Loaded glmnet 4.0-2 library(caret) ## Warning: package 'caret' was built under R version 4.0.3 ## Loading required package: lattice ## Loading required package: ggplot2 ## Warning: package 'ggplot2' was built under R version 4.0.2 For this assignment, we only need the following attributes: "Sales", "Price", "Advertising", "Population", "Age", "Income" and "Education". The goal of the assignment is to build models to predict the sales of the carseats (Sales attribute) using the other attributes. We can use the dplyr select function to select these attributes. Carseats_Filtered <- Carseats %>% select("Sales", "Price", "Advertising","Population","Age","Income","Education")

QB1. Build a Lasso regression model to predict Sales based on all other attributes ("Price", "Advertising", "Population", "Age", "Income" and "Education"). What is the best value of lambda for such a lasso model? (Hint1: Do not forget to scale your input attributes you can use the caret preprocess() function to scale and center the data. Hint 2: glment library expect the input attributes to be in the matrix format. You can use the as.matrix() function for converting)-- 20 Points QB2. What is the coefficient for the price (normalized) attribute in the best model (i.e. model with the optimal lambda)? --15 points QB3. How many attributes remain in the model if lambda is set to 0.01? How that number changes if lambda is increased to 0.1? Do you expect more variables to stay in the model (i.e., to have non-zero coefficients) as we increase lambda? 15 points QB4. Build an elastic-net model with alpha set to 0.6. What is the best value of lambda for such a model? 10 points

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!