【发布时间】:2018-05-21 18:18:41
【问题描述】:
我正在使用插入符号中的 CHAID 方法。我得到与post 相同的错误,即当所有 x 都是因子时,x 不是一个因子。
我正在使用 R 3.3.3 和 caret_6.0-78
这是一个玩具示例:
库(数据集) 图书馆(插入符号) 图书馆(CHAID)testDat<-data.frame(HairEyeColor, stringsAsFactors=T)[,1:3]
str(testDat)
'data.frame': 32 obs. of 3 variables:
$ Hair: Factor w/ 4 levels "Black","Brown",..: 1 2 3 4 1 2 3 4 1 2 ...
$ Eye : Factor w/ 4 levels "Brown","Blue",..: 1 1 1 1 2 2 2 2 3 3 ...
$ Sex : Factor w/ 2 levels "Male","Female": 1 1 1 1 1 1 1 1 1 1 ...
control <- trainControl(method="repeatedcv", number=10, repeats=3,
+ savePredictions="final", summaryFunction=twoClassSummary, classProbs=TRUE)
fit.chaid <- train(Sex~Hair+Eye, data=testDat, method="chaid", metric="ROC", trControl=control)
Error: is.factor(x) is not TRUE
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Timing stopped at: 0.02 0 0.02
warnings()
Warning messages:
1: model fit failed for Fold01.Rep1: alpha2=0.05, alpha3=-1, alpha4=0.05 Error : is.factor(x) is not TRUE
.
.
【问题讨论】:
-
一个小见解。这个问题是由于
caret而不是CHAID因为:ctrl <- chaid_control(minsplit = 200, minprob = 0.1)z <- chaid(Sex ~ ., data = testDat, control = ctrl)没有问题。