library(ISLR) # load the ISLR package # (a) Split the data set into a training set and a test set

本练习中,我们将利用ISLR包中的Collegdata数据集预测申请数量。步骤包括:将数据集划分为训练集和测试集各占一半,设定随机种子为1234;在训练集上分别应用最小二乘法、岭回归(通过交叉验证选择参数)和lasso回归(同样通过交叉验证选择参数),并报告各自在测试集上的均方误差(MSE)。
摘要由CSDN通过智能技术生成

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mrrunsen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值