我正在尝试使用插入符号进行变量选择,并且在某些类型的模型中同时出现错误。我在下面重现了一个错误:“{ 中的错误:任务 1 失败 - 下标越界”,但我也使用其他数据得到“{ 中的错误:任务 1 失败 - “替换有 XXX 行,数据有 YYY”。
我有兴趣解决这个特定的错误,以及如何解决这个问题的建议。谢谢。
library(caret)
data(iris)
predictors <- names(iris)[names(iris)!="Species"]
split <- createDataPartition(iris$Species, p = .8, list = FALSE)
irisData <- iris[,predictors]
irisData$Class <- iris$Species
training <- irisData[ split, ]
testing <- irisData[-split, ]
times <- 1
folds <- 5
prednumSeq <- seq(1, length(predictors)-1, by = 1)
ctrl <- rfeControl(method = "repeatedcv",
timingSamps = 2,
number = folds,
repeats = times,
saveDetails = TRUE,
verbose = TRUE,
allowParallel = FALSE)
rfRFE <- rfe(training[,predictors],
training$Class,
sizes = prednumSeq,
rfeControl = ctrl)
这导致:
+(rfe) fit Fold1.Rep1 size: 4
-(rfe) fit Fold1.Rep1 size: 4
+(rfe) imp Fold1.Rep1
+(rfe) fit Fold2.Rep1 size: 4
-(rfe) fit Fold2.Rep1 size: 4
+(rfe) imp Fold2.Rep1
+(rfe) fit Fold3.Rep1 size: 4
-(rfe) fit Fold3.Rep1 size: 4
+(rfe) imp Fold3.Rep1
+(rfe) fit Fold4.Rep1 size: 4
-(rfe) fit Fold4.Rep1 size: 4
+(rfe) imp Fold4.Rep1
+(rfe) fit Fold5.Rep1 size: 4
-(rfe) fit Fold5.Rep1 size: 4
+(rfe) imp Fold5.Rep1
Error in { : task 1 failed - "subscript out of bounds"
sessionInfo() 的详细信息是:
R version 3.0.0 (2013-04-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] MASS_7.3-26 randomForest_4.6-7 e1071_1.6-1 class_7.3-7
[5] pROC_1.5.4 caret_5.15-61 reshape2_1.2.2 plyr_1.8
[9] lattice_0.20-15 foreach_1.4.0 cluster_1.14.4
loaded via a namespace (and not attached):
[1] codetools_0.2-8 compiler_3.0.0 grid_3.0.0 iterators_1.0.6 stringr_0.6.2
[6] tools_3.0.0