【问题标题】:Use penalty.factor in stabsel in R在 R 的 stabsel 中使用惩罚因子
【发布时间】:2017-09-16 08:52:29
【问题描述】:

我想在 glmnet 套索之上使用 stabsel 进行变量选择。我按照https://github.com/hofnerb/stabs 上的示例进行操作,效果很好。

但是,我还想强制包含几个变量。这可以通过参数 'penalty.factor' 在 glmnet 中实现,但在 args.fitfun 中将此参数传递给 stabsel 会导致错误(见下文)。

data("bodyfat", package = "TH.data")
pfac=c(0,0,0,1,0,1,1,1,1)
stab.glmnet <- stabsel(x = bodyfat[, -2], y = bodyfat[,2],
                           fitfun = glmnet.lasso, cutoff = 0.75,
                           PFER = 1, args.fitfun=list(penalty.factor = pfac))
Error in res[[1]] : subscript out of bounds
In addition: Warning message:
In run_stabsel(fitter = fit_model, args.fitter = args.fitfun, n = n,      :
100 fold(s) encountered an error. Results are based on 0 folds only.
Original error message(s):
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
Error : Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x [... truncated]

任何帮助将不胜感激!

【问题讨论】:

    标签: r feature-selection glmnet stability


    【解决方案1】:

    我想通了。由于我们通过设置惩罚因子强制包含 n 个变量,因此我们需要调整三个 stabsel 变量(cutoff、PFER、q)以确保我们允许在每次重采样中选择至少 n 个变量。

    https://github.com/hofnerb/stabs/blob/master/README.mdhttp://onlinelibrary.wiley.com/doi/10.1111/j.1467-9868.2010.00740.x/full 更多细节。

    【讨论】:

      猜你喜欢
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 2015-03-05
      • 2016-03-30
      • 2012-11-11
      • 1970-01-01
      • 2012-05-12
      相关资源
      最近更新 更多