2017-05-08 91 views
0

我想重複的代碼下面幾行:如何應用套索與glmnet進行套索邏輯迴歸?

x.mat <- as.matrix(train.df[,predictors]) 
y.class <- train.df$Response 

cv.lasso.fit <- cv.glmnet(x = x.mat, y = y.class, 
          family = "binomial", alpha = 1, nfolds = 10) 

...與插入符號包,但它不工作:

trainControl <- trainControl(method = "cv", 
         number = 10, 
         # Compute Recall, Precision, F-Measure 
         summaryFunction = prSummary, 
         # prSummary needs calculated class probs 
         classProbs = T) 

modelFit <- train(Response ~ . -Id, data = train.df, 
      method = "glmnet", 
      trControl = trainControl, 
      metric = "F", # Optimize by F-measure 
      alpha=1, 
      family="binomial") 

參數「阿爾法」無法識別,「模型適合每次都失敗」。

我在做什麼錯?幫助將不勝感激。謝謝。

回答

1

嘗試使用tuneGrid。例如如下:

tuneGrid=expand.grid(
       .alpha=1, 
       .lambda=seq(0, 100, by = 0.1)) 
+0

非常感謝!這解決了它。 – CodingButStillAlive