Question 4
In this exercise. we will predict the number of applications received using the other variables in the Collegdata set from the ISLR package
(a) Split the data set into a training set and a test set each containing half the data set. Set the random seeas 1234, i.e. set.seed(1234) and use the sample() function to pseudo-randomly determine the indicof observations in the training set, i.e. train.idx = sample(# observations in full sample,observations in the training set): You would include these observations in the training set, anexclude them from the test set
(b) Fit a linear model using least squares on the training set, and report the test error (MSE) obtainedYou can obtain the fitted values using the predict() function, ie. predict(fit, test data).© Fit a ridge regression model on the training set, with > chosen by cross-validation. Report the teserror obtained.
(d) Fit a lasso model on the training set, with chosen by cross-validation. Re
library(ISLR) # load the ISLR package # (a) Split the data set into a training set and a test set
![](https://img-home.csdnimg.cn/images/20240711042549.png)