1

データセットがあり、データセットの特定の部分のみでキャレットをトレーニングして検証したいと考えています。私は2つのリストを持っています

train.ids <- list(T1=c(1,2,3), T2=c(4,5,6), T3=c(7,8,9))

test.ids <- list(T1=c(10,11,12), T2=c(13,14,15), T3=(16,17,18))

これは、データ セットの行インデックスに対応します。train.ids$T1テストには使用する必要がありますが、トレーニングには使用するtest.ids$T1必要があります。T2 と T3 についても同様です。

使ってみた

trainControl(method="cv", index=train.ids, indexOut=test.ids)

しかし、これは trainControl を使用する正しい方法ではないようです。

どんな助けでも大歓迎です

4

1 に答える 1

3

エラーが発生しましたか? なぜこれがうまくいかないのかわかりません。次に例を示します。

library(caret)

## A small data set example
set.seed(2)
dat <- twoClassSim(9)[, 13: 16]

fit_on <-  list(rs1 = 1:3, rs2 = 4:6,         rs3 = 7:9)
pred_on <- list(rs1 = 4:9, rs2 = c(1:3, 7:9), rs3 = 1:6)

ctrl <- trainControl(method = "cv", 
                     ## The method doesn't really matter
                     ## since we are defining the resamples
                     index= fit_on, indexOut = pred_on,
                     verboseIter = TRUE,
                     savePredictions = TRUE)

mod <- train(Class ~ ., data = dat, method = "lda",
             trControl = ctrl)

を見てみるmod$predと、各反復で何が予測されたかがわかります。

マックス

于 2014-04-30T01:54:32.170 に答える