Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mlr:将学习者用作过滤器_R_Mlr - Fatal编程技术网

mlr:将学习者用作过滤器

mlr:将学习者用作过滤器,r,mlr,R,Mlr,我想创建一个自定义过滤器,该过滤器使用LASSO方法(glmnet,alpha=1)来选择特征,即glmnet分配非零系数的特征是所选特征。我希望glmnet作为过滤器的原因是,这样我就可以在重新采样期间将这些选定的功能提供给另一个学习者 为了避免重新发明轮子,我在过滤器中使用了makeLearner,但我不确定这是否是一个有效的方法。这就是我所拥有的(我只对这个阶段的生存数据感兴趣): 我的问题是-使用makeLearner然后在过滤器中训练该学习者可以吗?有更好的方法吗?你读过吗?如果你走这

我想创建一个自定义过滤器,该过滤器使用LASSO方法(glmnet,alpha=1)来选择特征,即glmnet分配非零系数的特征是所选特征。我希望glmnet作为过滤器的原因是,这样我就可以在重新采样期间将这些选定的功能提供给另一个学习者

为了避免重新发明轮子,我在过滤器中使用了makeLearner,但我不确定这是否是一个有效的方法。这就是我所拥有的(我只对这个阶段的生存数据感兴趣):


我的问题是-使用makeLearner然后在过滤器中训练该学习者可以吗?有更好的方法吗?

你读过吗?如果你走这条路,我们也欢迎你的公关。Lasso filter是我们已经考虑过的一种集成方法。在进行过滤时,也不要忘记使用缓存,这使得此操作几乎是即时的。@pat-s你是说这是正确的方法吗?如果可以的话,我很高兴为这个包做贡献,我计划写其他类似的过滤器,但我不确定我是否足够了解更精细的细节。有关于缓存的文档吗?最终的实现需要更加通用,使用
cvglmnet
,而不是针对生存模型进行定制。我还没有详细查看代码的所有部分。但捐款总是受欢迎的。有关缓存信息,请参阅。
makeFilter(
  name = "LASSO.surv",
  desc = "Use the LASSO method to select features for survival data",
  pkg = "glmnet",
  supported.tasks = c("surv"),
  supported.features = c("numerics", "factors", "ordered"),
  fun = function(task, nselect, folds, ...) {

    data = getTaskData(task, target.extra = TRUE, recode.target = "surv")

    lasso.lrn = makeLearner(cl="surv.cvglmnet", id = "lasso", predict.type="response", alpha = 1, nfolds=folds)
    model = train(lasso.lrn, task)
    mod = model$learner.model

    coef.min =coef(mod, s=mod$lambda.min)
    res<-as.matrix(coef.min)[,1]
    active.min = which(as.matrix(coef.min) != 0)
    res[active.min]
  })
task = wpbc.task
inner = makeResampleDesc("CV", iters=5, stratify=TRUE)  # Tuning

cox.lrn <- makeLearner(cl="surv.coxph", id = "coxph", predict.type="response")
cox.filt.lrn =   makeFilterWrapper(
  makeLearner(cl="surv.coxph", id = "cox.filt", predict.type="response"), 
  fw.method="LASSO.surv", 
  fw.perc=0.5,
  folds=5
)
learners = list(cox.lrn, cox.filt.lrn)
benchmark(learners, task, inner, measures=list(cindex), show.info=TRUE)
Task: wpbc-example, Learner: coxph
Resampling: cross-validation
Measures:             cindex    
[Resample] iter 1:    0.5884477 
[Resample] iter 2:    0.6355556 
[Resample] iter 3:    0.5333333 
[Resample] iter 4:    0.5256410 
[Resample] iter 5:    0.7142857 


Aggregated Result: cindex.test.mean=0.5994527


Task: wpbc-example, Learner: cox.filt.filtered
Resampling: cross-validation
Measures:             cindex    
[Resample] iter 1:    0.5379061 
[Resample] iter 2:    0.6533333 
[Resample] iter 3:    0.7022222 
[Resample] iter 4:    0.6452991 
[Resample] iter 5:    0.6764706 


Aggregated Result: cindex.test.mean=0.6430463


       task.id        learner.id cindex.test.mean
1 wpbc-example             coxph        0.5994527
2 wpbc-example cox.filt.filtered        0.6430463