我想比较简单的逻辑回归模型,其中每个模型仅考虑指定的一组功能。我想对这些回归模型进行比较。
。 R软件包mlr
允许我使用dropFeatures
在任务级别选择列。代码将是:
full_task = makeClassifTask(id = "full task", data = my_data, target = "target")
reduced_task = dropFeatures(full_task, setdiff( getTaskFeatureNames(full_task), list_feat_keep))
然后,我可以进行具有任务列表的基准实验。
lrn = makeLearner("classif.logreg", predict.type = "prob")
rdesc = makeResampleDesc(method = "Bootstrap", iters = 50, stratify = TRUE)
bmr = benchmark(lrn, list(full_task, reduced_task), rdesc, measures = auc, show.info = FALSE)
我如何生成一个仅考虑指定功能集的学习者。据我所知,过滤器或选择方法始终应用一些统计过程,但不允许直接选择功能。谢谢!
第一个解决方案是懒惰的,也不是最佳的,因为过滤器计算仍在执行:
library(mlr)
task = sonar.task
sel.feats = c("V1", "V10")
lrn = makeLearner("classif.logreg", predict.type = "prob")
lrn.reduced = makeFilterWrapper(learner = lrn, fw.method = "variance", fw.abs = 2, fw.mandatory.feat = sel.feats)
bmr = benchmark(list(lrn, lrn.reduced), task, cv3, measures = auc, show.info = FALSE)
第二个使用预处理包装器来过滤数据,应该是最快的解决方案,并且也更加灵活:
lrn.reduced.2 = makePreprocWrapper(
learner = lrn,
train = function(data, target, args) list(data = data[, c(sel.feats, target)], control = list()),
predict = function(data, target, args, control) data[, sel.feats]
)
bmr = benchmark(list(lrn, lrn.reduced.2), task, cv3, measures = auc, show.info = FALSE)