通过插入符号::train()运行时,enet()不起作用

通过插入符号::train()运行时,enet()不起作用,r,machine-learning,r-caret,R,Machine Learning,R Caret,我在试着用一张有弹性的网。从套索开始,从那里开始。我可以让它直接运行,但当我尝试使用caret包中的train运行相同的参数时,它失败了。我想让train工作,以便我可以使用它来评估模型参数 # Works test <- enet( x=x, y=y, lambda=0, trace=TRUE, normalize=FALSE, intercept=FALSE ) # Doesn't enetGrid <- data.frame(.lambda=0,.fraction=c(.01,

我在试着用一张有弹性的网。从套索开始,从那里开始。我可以让它直接运行,但当我尝试使用
caret
包中的
train
运行相同的参数时,它失败了。我想让
train
工作,以便我可以使用它来评估模型参数

# Works
test <- enet( x=x, y=y, lambda=0, trace=TRUE, normalize=FALSE, intercept=FALSE )
# Doesn't
enetGrid <- data.frame(.lambda=0,.fraction=c(.01,.001,.0005,.0001))
ctrl <- trainControl( method="repeatedcv", repeats=5 )
> test2 <- train( x, y, method="enet", tuneGrid=enetGrid, trControl=ctrl, preProc=NULL )
  fraction lambda RMSE Rsquared RMSESD RsquaredSD
1    1e-04      0  NaN      NaN     NA         NA
2    5e-04      0  NaN      NaN     NA         NA
3    1e-03      0  NaN      NaN     NA         NA
4    1e-02      0  NaN      NaN     NA         NA
Error in train.default(x, y, method = "enet", tuneGrid = enetGrid, trControl = ctrl,  : 
  final tuning parameters could not be determined
In addition: There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
...
50: In eval(expr, envir, enclos) :
  model fit failed for Fold10.Rep5: lambda=0, fraction=0.01 Error in enet(as.matrix(trainX), trainY, lambda = lmbda) : 
  Some of the columns of x have zero variance
更新

在数据集的15%样本上运行:

Warning in eval(expr, envir, enclos) :
  model fit failed for Fold10.Rep1: lambda=0, fraction=0.005
... (more of the same warning messages) ...
Warning in nominalTrainWorkflow(dat = trainData, info = trainInfo, method = met\
hod,  :
  There were missing values in resampled performance measures.
Error in if (lambda > 0) { : argument is of length zero
Calls: train ... train.default -> system.time -> createModel -> enet

X矩阵有806列,其中801列是虚拟列。这些假人中有许多非常稀疏(25k左右的行中有1-3个观察值),其他的有0.1-5%的值为真。总共有108867个真的和21mm假的。

为了解决这个问题,我现在让它工作起来。我删除了所有小于20个
TRUE
的列(记住,这是近200000个观察值中的一个),因为没有足够的信息来提供。结果是他们中的一半

在我前进的过程中,我必须小心这些稀疏列不会造成太多的偏差等,但我希望通过使用一种进行变量选择(套索、RF等)的方法,问题会少一些


感谢@O_Devinyak的帮助。

这个问题似乎离题了,因为它是关于诱使R做你想做的事情,或者使用一个包,而不是一个统计问题。@GavinSimpson我想在这里更合适,但我想不是。标记为迁移到SO。您是否在运行
train()
时收到任何错误消息?如果主要问题是共线性,可能的方法之一是在运行
train()
之前向数据添加小的(相对于列的标准差)随机错误。这是二次采样的问题。在运行交叉验证时,某些样本的绘制方式会使某些列变为常量。在enet使用的整个数据中没有常量列,因此enet()可以正常工作。但在用于交叉验证的样本中,它们是。
Warning in eval(expr, envir, enclos) :
  model fit failed for Fold10.Rep1: lambda=0, fraction=0.005
... (more of the same warning messages) ...
Warning in nominalTrainWorkflow(dat = trainData, info = trainInfo, method = met\
hod,  :
  There were missing values in resampled performance measures.
Error in if (lambda > 0) { : argument is of length zero
Calls: train ... train.default -> system.time -> createModel -> enet