Rキャレット(参照番号:this example)を使用してクロス検証を行いたいが、CVモデルを作成するためのトレーニングでデータのサブセットのみを使用する。それでも、計算された制約のためにトレーニングに使用できない数百万のサンプルであっても、左の被験者のすべてのデータをテストする必要があるため、左のCVパーティションを全体として使用する必要があります。Rキャレット:トレーニングのためにデータサブセットを使用してクロス検証を行いますか?
私はこれを達成するためにcaret::train
とcaret::trainControl
のsubset
とindex
パラメータを使用して、最小限の2クラス分類の例を作成しました。私の見解では、これで問題は解決するはずですが、実際にはという評価は、依然として対象外の方法で行われています。。たぶん、このタスクの経験を持つ誰かがこの上でいくつかの光を当てることができます:
library(plyr)
library(caret)
library(pROC)
library(ggplot2)
# with diamonds we want to predict cut and look at results for different colors = subjects
d <- diamonds
d <- d[d$cut %in% c('Premium', 'Ideal'),] # make a 2 class problem
d$cut <- factor(d$cut)
indexes_data <- c(1,5,6,8:10)
indexes_labels <- 2
# population independent CV indexes for trainControl
index <- llply(unique(d[,3]), function(cls) c(which(d[,3]!=cls)))
names(index) <- paste0('sub_', unique(d[,3]))
str(index) # indexes used for training models with CV = OK
m3 <- train(x = d[,indexes_data],
y = d[,indexes_labels],
method = 'glm',
metric = 'ROC',
subset = sample(nrow(d), 5000), # does this subset the data used for training and obtaining models, but not the left out partition used for estimating CV performance?
trControl = trainControl(returnResamp = 'final',
savePredictions = T,
classProbs = T,
summaryFunction = twoClassSummary,
index = index))
str(m3$resample) # all samples used once = OK
# performance over all subjects
myRoc <- roc(predictor = m3$pred[,3], response = m3$pred$obs)
プロット(myRoc、メイン= 'すべて')
個々の被験者のパフォーマンス
l_ply(ユニーク(M3 $ PRED (予測子= pred_sub [、3]、応答= pred_sub $ obs)$ {$ resample}、.fun = function(cls){ pred_sub < - m3 $ pred [m3 $ pred $ Resample == cls、] myRoc < プロット(myRoc、main = cls) })
お時間をありがとうございます!同時にcaret::trainControl
でindex
とindexOut
パラメータの両方を使用して