我正在尝试调整rpart
。我已经将我的数据拆分为训练集和简历集。tune.rpart
便利功能似乎没有办法指定 cv 集。所以我正在使用常规tune()
功能。
我的数据集中有 595 个潜在变量,所以我不想使用公式来指定。执行此操作时出现以下错误
Error in tune(rpart, train.x = trainset[, -1], train.y = trainset[, 1], :
Dependent variable has wrong type!
In addition: Warning message:
In if (y) ans$y <- Y :
the condition has length > 1 and only the first element will be used
代码:
load('train.dat')
load('cv.dat')
trainset$class<-factor(trainset$class)
cvset$class<-factor(cvset$class)
rpart.tune<-tune(rpart,train.x= trainset[,-1], train.y=trainset[,1],
validation.x=cvset[,-1], validation.y=cvset[,1],
ranges = list(
cp = c(0.002,0.005,0.01,0.015,0.02,0.03)),
tunecontrol = tune.control(sampling = "fix"))
数据位于: https ://docs.google.com/folder/d/0B2_rKFnvrjMAM3FGbnFvZm5laUk/edit