Applying k-fold Cross Validation model using caret package

前端 未结 3 1262
-上瘾入骨i
-上瘾入骨i 2020-12-23 15:50

Let me start by saying that I have read many posts on Cross Validation and it seems there is much confusion out there. My understanding of that it is simply this:

3条回答
  •  情话喂你
    2020-12-23 16:03

    when you perform k-fold cross validation you are already making a prediction for each sample, just over 10 different models (presuming k = 10). There is no need make a prediction on the complete data, as you already have their predictions from the k different models.

    What you can do is the following:

    train_control<- trainControl(method="cv", number=10, savePredictions = TRUE)
    

    Then

    model<- train(resp~., data=mydat, trControl=train_control, method="rpart")
    

    if you want to see the observed and predictions in a nice format you simply type:

    model$pred
    

    Also for the second part of your question, caret should handle all the parameter stuff. You can manually try tune parameters if you desire.

提交回复
热议问题