我正在尝试使用 MLR 包来调整使用 rpart 包构建的决策树的超参数。即使我可以调整决策树的基本参数(例如minsplit
,maxdepth
等等),我也无法正确设置参数的值param
。具体来说,我想priors
在网格搜索中尝试不同。
这是我编写的代码(dat
是我正在使用的数据框,target
也是我的类变量):
# Create a task
dat.task = makeClassifTask(id = "tree", data = dat, target = "target")
# Define the model
resamp = makeResampleDesc("CV", iters = 4L)
# Create the learner
lrn = makeLearner("classif.rpart")
# Create the grid params
control.grid = makeTuneControlGrid()
ps = makeParamSet(
makeDiscreteParam("cp", values = seq(0.001, 0.006, 0.002)),
makeDiscreteParam("minsplit", values = c(1, 5, 10, 50)),
makeDiscreteParam("maxdepth", values = c(20, 30, 50)),
makeDiscreteParam("parms", values = list(prior=list(c(.6, .4),
c(.5, .5))))
)
当我尝试执行调整时,使用:
# Actual tuning, with accuracy as evaluation metric
tuned = tuneParams(lrn, task = dat.task,
resampling = resamp,
control = control.grid,
par.set = ps, measures = acc)
我得到错误
Error in get(paste("rpart", method, sep = "."), envir = environment())(Y, : The parms list must have names
我也尝试定义parms
为UntypedParam
with
makeUntypedParam("parms", special.vals = list(prior=list(c(.6, .4), c(.5,.5))))
这是因为通过键入getParamSet("classif.rpart")
,在我看来调整接受“无类型变量”而不是离散变量。
但是,当我尝试这个时,我得到了错误:
Error in makeOptPath(par.set, y.names, minimize, add.transformed.x, include.error.message, :
OptPath can currently only be used for: numeric,integer,numericvector,integervector,logical,logicalvector,discrete,discretevector,character,charactervector
有人可以帮忙吗?