【问题标题】:CHAID with r-caret error x is not a factor带有 r-caret 错误 x 的 CHAID 不是一个因素
【发布时间】: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 &lt;- chaid_control(minsplit = 200, minprob = 0.1) z &lt;- chaid(Sex ~ ., data = testDat, control = ctrl) 没有问题。

标签: r r-caret


【解决方案1】:

我知道这个问题已经很老了,但在这里我通过实验得到了答案:

对于 CHAID 建模,尝试使用 xy 建模而不是公式建模,如下所示:

fit.chaid <- train(x=testDat[,c(1,2)], #Hair and Eye Variable
y=testDat[,c(3)],  #Sex Variable
method="chaid", 
metric="ROC", 
trControl=control)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-29
    • 2015-08-17
    • 2015-09-04
    • 1970-01-01
    • 1970-01-01
    • 2013-06-23
    • 2018-06-09
    相关资源
    最近更新 更多