我想知道如何恢复交叉验证的预测结果。我有兴趣手动构建一个堆叠模型(像这里的3.2.1点), 我需要每个保留折叠的模型预测结果。这里附上一个简短的示例。
# load the library
library(caret)
# load the iris dataset
data(cars)
# define folds
cv_folds <- createFolds(cars$Price, k = 5, list = TRUE)
# define training control
train_control <- trainControl(method="cv", index = cv_folds, savePredictions = 'final')
# fix the parameters of the algorithm
# train the model
model <- caret::train(Price~., data=cars, trControl=train_control, method="gbm", verbose = F)
# looking at predictions
model$pred
# verifying the number of observations
nrow(model$pred[model$pred$Resample == "Fold1",])
nrow(cars)
我想知道在对1-4折叠的模型进行估计并在第5折上进行评估时,会有哪些预测结果。看起来,查看
model$pred
并不能给我所需的信息。
subset(model$pred, Resample == "Fold01")
时,我得到的数据框大小等于用于估计的9个折叠。然而,我想要得到的是相反的,也就是未用于估计的10%数据的预测结果。 - abunrow(model$pred[model$pred$Resample == "Fold01",])
是 80,而nrow(cars)
是 804。 - missusenrow
。 - abu