首先,我要说我已经阅读了许多关于交叉验证的文章,似乎存在很多困惑。我理解的是:
- 进行k折交叉验证,例如10个fold,以了解在这10个fold中的平均误差。
- 如果可接受,则在完整数据集上训练模型。
我正尝试使用R中的rpart
构建决策树,并利用caret
包。以下是我使用的代码。
# load libraries
library(caret)
library(rpart)
# define training control
train_control<- trainControl(method="cv", number=10)
# train the model
model<- train(resp~., data=mydat, trControl=train_control, method="rpart")
# make predictions
predictions<- predict(model,mydat)
# append predictions
mydat<- cbind(mydat,predictions)
# summarize results
confusionMatrix<- confusionMatrix(mydat$predictions,mydat$resp)
关于 caret train 应用,我有一个问题。我已经阅读了 A Short Introduction to the caret Package 中的 train 部分,其中指出在重采样过程中确定了“最优参数集”。
在我的示例中,我是否已正确编写代码?我是否需要在我的代码中定义 rpart
参数,还是我的代码已足够?