LASSO的R功能选择

问题描述

我有一个小的数据集(37个观测值x 23个特征),并希望通过LASSO回归进行特征选择,以减小其维数。为此,我根据在线教程设计了以下代码

#Load the libraries
library(mlbench)
library(elasticnet)
library(caret)

#Initialize cross validation and train LASSO
cv_5 <- trainControl(method="cv",number=5)
lasso <- train( ColumnY ~.,data=My_Data_Frame,method='lasso',trControl=cv_5)

#Filter out the variables whose coefficients have squeezed to 0
drop <-predict.enet(lasso$finalModel,type='coefficients',s=lasso$bestTune$fraction,mode='fraction')$coefficients  
drop<-drop[drop==0]%>%names()
My_Data_Frame<- My_Data_Frame%>%select(-drop) 

在大多数情况下,代码可以正常运行,但偶尔会引发以下情况:

Warning messages:
1: model fit failed for Fold2: fraction=0.9 Error in if (zmin < gamhat) { : missing value where TRUE/FALSE needed
 
2: In nominalTrainWorkflow(x = x,y = y,wts = weights,info = trainInfo,:
  There were missing values in resampled performance measures.

我之所以会这样,是因为我的数据行很少,而某些变量的方差很小。 有什么方法可以绕过或解决此问题(例如,在流程中设置参数)?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)