ml教程的这一部分:https://mlr.mlr-org.com/articles/tutorial/nested_resampling.html#filter-methods-with-tuning 解释了如何使用带有FilterWrapper的TuneWrapper来调整过滤器的阈值。但是,如果我的筛选器具有需要调整的超参数,例如随机森林变量重要性筛选器,该怎么办?除了阈值之外,我似乎无法调整任何参数。
例如:
library(survival)
library(mlr)
data(veteran)
set.seed(24601)
task_id = "MAS"
mas.task <- makeSurvTask(id = task_id, data = veteran, target = c("time", "status"))
mas.task <- createDummyFeatures(mas.task)
tuning = makeResampleDesc("CV", iters=5, stratify=TRUE) # Tuning: 5-fold CV, no repeats
cox.filt.rsfrc.lrn = makeTuneWrapper(
makeFilterWrapper(
makeLearner(cl="surv.coxph", id = "cox.filt.rfsrc", predict.type="response"),
fw.method="randomForestSRC_importance",
cache=TRUE,
ntree=2000
),
resampling = tuning,
par.set = makeParamSet(
makeIntegerParam("fw.abs", lower=2, upper=10),
makeIntegerParam("mtry", lower = 5, upper = 15),
makeIntegerParam("nodesize", lower=3, upper=25)
),
control = makeTuneControlRandom(maxit=20),
show.info = TRUE)
生成错误消息:
检查调谐器Parset(learner, par.set, measure, control( 中的错误: 只能调整存在学习器参数的参数:mtry,nodesize
有没有办法调整随机森林的超参数?
编辑:其他尝试遵循评论中的建议:
在馈送到过滤器之前将调谐器包裹在基本学习器周围(未显示过滤器( - 失败
cox.lrn = makeLearner(cl="surv.coxph", id = "cox.filt.rfsrc", predict.type="response") cox.tune = makeTuneWrapper(cox.lrn, resampling = tuning, measures=list(cindex), par.set = makeParamSet( makeIntegerParam("mtry", lower = 5, upper = 15), makeIntegerParam("nodesize", lower=3, upper=25), makeIntegerParam("fw.abs", lower=2, upper=10) ), control = makeTuneControlRandom(maxit=20), show.info = TRUE) Error in checkTunerParset(learner, par.set, measures, control) : Can only tune parameters for which learner parameters exist: mtry,nodesize,fw.abs
两个级别的调整 - 失败
cox.lrn = makeLearner(cl="surv.coxph", id = "cox.filt.rfsrc", predict.type="response") cox.filt = makeFilterWrapper(cox.lrn, fw.method="randomForestSRC_importance", cache=TRUE, ntree=2000) cox.tune = makeTuneWrapper(cox.filt, resampling = tuning, measures=list(cindex), par.set = makeParamSet( makeIntegerParam("fw.abs", lower=2, upper=10) ), control = makeTuneControlRandom(maxit=20), show.info = TRUE) cox.tune2 = makeTuneWrapper(cox.tune, resampling = tuning, measures=list(cindex), par.set = makeParamSet( makeIntegerParam("mtry", lower = 5, upper = 15), makeIntegerParam("nodesize", lower=3, upper=25) ), control = makeTuneControlRandom(maxit=20), show.info = TRUE) Error in makeBaseWrapper(id, learner$type, learner, learner.subclass = c(learner.subclass, : Cannot wrap a tuning wrapper around another optimization wrapper!
看起来您目前无法调整过滤器的超参数。您可以通过传入makeFilterWrapper()
来手动更改某些参数,但不能对其进行调整。 在过滤方面,您只能调整fw.abs
、fw.perc
或fw.tresh
之一。
我不知道当对随机森林过滤器使用不同的超标准时,对排名的影响有多大。检查鲁棒性的一种方法是在getFeatureImportance()
的帮助下,使用不同的设置来比较单个RF模型拟合的排名,供mtry
和朋友使用。如果它们之间存在非常高的秩相关性,则可以安全地忽略RF滤波器的调谐。(也许您想使用此问题根本不附带的其他过滤器?
如果您坚持使用此功能,则可能需要为包:)提出 PR
lrn = makeLearner(cl = "surv.coxph", id = "cox.filt.rfsrc", predict.type = "response")
filter_wrapper = makeFilterWrapper(
lrn,
fw.method = "randomForestSRC_importance",
cache = TRUE,
ntrees = 2000
)
cox.filt.rsfrc.lrn = makeTuneWrapper(
filter_wrapper,
resampling = tuning,
par.set = makeParamSet(
makeIntegerParam("fw.abs", lower = 2, upper = 10)
),
control = makeTuneControlRandom(maxit = 20),
show.info = TRUE)