Caret train方法抱怨有问题;缺少所有RMSE指标值

时间:2015-07-28 19:48:15

标签: r r-caret rpart gbm

在尝试适合gbm或rpart模型时,我多次遇到此错误。最后,我能够使用公开数据一致地重现它。我注意到使用CV(或重复的cv)时会发生此错误。当我不使用任何适合控制时,我不会收到此错误。有些人可以说清楚为什么我一直都会得到错误。

fitControl= trainControl("repeatedcv", repeats=5)
ds = read.csv("http://www.math.smith.edu/r/data/help.csv")
ds$sub = as.factor(ds$substance)
rpartFit1 <- train(homeless ~ female + i1 + sub + sexrisk + mcs + pcs, 
                   tcControl=fitControl, 
                   method = "rpart", 
                   data=ds)

1 个答案:

答案 0 :(得分:1)

有一个错字,应该是trControl而不是tcControl。并且当参数以tcControl的形式提供时,caret将此参数传递给rpart并抛出错误,因为该选项从不可用。

我想这回答了您的问题,即在尝试进行交叉验证时为什么会出现此错误。

下面是它的工作方式:

library(caret)
library(mosaicData)

data(HELPrct)
ds = HELPrct
fitControl= trainControl(method="repeatedcv",times=5)
ds$sub = as.factor(ds$substance)

rpartFit1 <- train(homeless ~ female + i1 + sub + sexrisk + mcs + pcs, 
                   trControl=fitControl, 
                   method = "rpart", 
                   data=ds[complete.cases(ds),])

rpartFit1
CART 

117 samples
  6 predictor
  2 classes: 'homeless', 'housed' 

No pre-processing
Resampling: Cross-Validated (10 fold) 
Summary of sample sizes: 105, 105, 105, 106, 105, 106, ... 
Resampling results across tuning parameters:

  cp          Accuracy   Kappa      
  0.00000000  0.5280303  -0.03503032
  0.01190476  0.5280303  -0.03503032
  0.07142857  0.5977273  -0.02970604

Accuracy was used to select the optimal model using the largest value.
The final value used for the model was cp = 0.07142857.