変数の選択にキャレットを使用しようとしていますが、いくつかのタイプのモデルで同じポイントでエラーが発生します。以下の 1 つのエラーを再現します:「{ のエラー: タスク 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