質問

私はRにモデルをフィットしています

  • 使用する createFolds いくつかを作成する方法 k データセットからの折りたたみ
  • 折り目をループし、各反復で以下を繰り返します。
    • train K-1折りたたみのモデル
    • predict i-th foldの結果
    • 予測精度を計算します
  • 正確性を平均します

Rには、折りたたみを作成し、モデルの調整/予測を繰り返し、平均精度を戻す関数がありますか?

役に立ちましたか?

解決

はい、あなたはカレットを使用してこれをすべて行うことができます(http://caret.r-forge.r-project.org/training.html)R。たとえば、パッケージ、たとえば、

fitControl <- trainControl(## 10-fold CV
                           method = "repeatedcv",
                           number = 10,
                           ## repeated ten times
                           repeats = 10)

gbmFit1 <- train(Class ~ ., data = training,
                 method = "gbm",
                 trControl = fitControl,
                ## This last option is actually one
                ## for gbm() that passes through
                verbose = FALSE)
gbmFit1

出力が得られます

Stochastic Gradient Boosting 

157 samples
 60 predictors
  2 classes: 'M', 'R' 

No pre-processing
Resampling: Cross-Validated (10 fold, repeated 10 times) 

Summary of sample sizes: 142, 142, 140, 142, 142, 141, ... 

Resampling results across tuning parameters:

  interaction.depth  n.trees  Accuracy  Kappa  Accuracy SD  Kappa SD
  1                  50       0.8       0.5    0.1          0.2     
  1                  100      0.8       0.6    0.1          0.2     
  1                  200      0.8       0.6    0.09         0.2     
  2                  50       0.8       0.6    0.1          0.2     
  2                  100      0.8       0.6    0.09         0.2     
  2                  200      0.8       0.6    0.1          0.2     
  3                  50       0.8       0.6    0.09         0.2     
  3                  100      0.8       0.6    0.09         0.2     
  3                  200      0.8       0.6    0.08         0.2     

Tuning parameter 'shrinkage' was held constant at a value of 0.1
Accuracy was used to select the optimal model using  the largest value.
The final values used for the model were n.trees = 150, interaction.depth = 3     
and shrinkage = 0.1.

CARETは他の多くのオプションも提供しているため、ニーズに合わせることができるはずです。

ライセンス: CC-BY-SA帰属
所属していません datascience.stackexchange
scroll top