2015-02-06 21 views
1

这里第一次海报,所以对于菜鸟错误致歉歉在插入符号的交叉验证过程中计算模型校准?

我在使用R中的脱字符包进行分类。我使用训练集上的重复10倍交叉验证来拟合一些模型(GBM,线性SVM,NB,LDA)。通过使用自定义的trainControl,caret甚至可以为我提供一系列模型性能指标,例如ROC,Spec/sens,Kappa,Accuracy over the test folds。这真的太棒了。还有一个我喜欢的度量标准:模型校准的一些度量。

我注意到插入符号内有一个function可以创建一个校准图来估计模型性能在数据部分的一致性。在交叉验证的模型构建过程中,是否可以用插入符号计算每个测试折叠的结果?还是只能应用于我们正在进行预测的一些新的数据呢?

对于某些方面,在现阶段,我有这样的事情:

fitControl <- trainControl(method = "repeatedcv", repeats=2, number = 10, classProbs = TRUE, summaryFunction = custom.summary) 
gbmGrid <- expand.grid(.interaction.depth = c(1,2,3),.n.trees = seq(100,800,by=100),.shrinkage = c(0.01)) 
gbmModel <- train(y= train_target, x = data.frame(t_train_predictors), 
       method = "gbm", 
       trControl = fitControl, 
       tuneGrid = gbmGrid, 
       verbose = FALSE) 

如果有帮助,我使用〜25个的数字预测和N = 2,200预测两类因素。

非常感谢您的任何帮助/建议。 亚当

回答

5

calibration函数将采取您给它的任何数据。您可以从train子对象pred获得重采样值:

> set.seed(1) 
> dat <- twoClassSim(2000) 
> 
> set.seed(2) 
> mod <- train(Class ~ ., data = dat, 
+    method = "lda", 
+    trControl = trainControl(savePredictions = TRUE, 
+          classProbs = TRUE)) 
> 
> str(mod$pred) 
'data.frame': 18413 obs. of 7 variables: 
$ pred  : Factor w/ 2 levels "Class1","Class2": 1 2 2 1 1 2 1 1 2 1 ... 
$ obs  : Factor w/ 2 levels "Class1","Class2": 1 2 2 1 1 2 1 1 2 2 ... 
$ Class1 : num 0.631 0.018 0.138 0.686 0.926 ... 
$ Class2 : num 0.369 0.982 0.8616 0.3139 0.0744 ... 
$ rowIndex : int 1 3 4 10 12 13 18 22 25 27 ... 
$ parameter: Factor w/ 1 level "none": 1 1 1 1 1 1 1 1 1 1 ... 
$ Resample : chr "Resample01" "Resample01" "Resample01" "Resample01" ... 

那么你可以使用:

> cal <- calibration(obs ~ Class1, data = mod$pred) 
> xyplot(cal) 

只要记住的是,与许多重采样方法,单一的训练集实例会是持有了多次:

> table(table(mod$pred$rowIndex)) 

    2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 
    2 11 30 77 135 209 332 314 307 231 185 93 48 16 6 4 

,如果你喜欢,你可以平均每个rowIndex类的概率。

最大

+0

Ooo谢谢!这就是我想的 - 谢谢你的解决方案。我想提高您的解决方案,但我还没有任何声望。再次感谢您的帮助和伟大的软件包Max。 – Achekroud 2015-02-20 00:41:27