-
在R语言中,使用 Chickweight 数据进行预测1进行5倍的交叉验证,重复抽样1000,用 Tme,Chck和成De预测 Weight
-
比较 GLM,RRM 以及 LASSO 模型的预测准确率。
-
讨论结果并说出自己的推测。
运行代码、运行结果、结果分析
options(digits = 4,scipen = 10)
library(caret)
ctrl <- trainControl(repeats = 5,number = 1000)
glmFit <- train(weight ~ Time + Chick + Diet ,
data = ChickWeight,
method = "glm",
trControl = ctrl)
ridgeFit <- train(weight ~ Time + Chick + Diet ,
data = ChickWeight,
method = "ridge",
trControl = ctrl)
lassoFit <- train(weight ~ Time + Chick + Diet ,
data = ChickWeight,
method = "lasso",
trControl = ctrl)
### 查看结果
glmFit$results$Rsquared
ridgeFit$results$Rsquared
lassoFit$results$Rsquared