在很多情况下,我在尝试安装时都会遇到此错误gbm
or 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)
有错别字,应该是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.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)