" glm"中的调整参数vs" rf"

时间:2017-05-15 02:38:09

标签: r logistic-regression glm cross-validation rpart

我正在尝试使用method = "glm"中的train来构建分类模型。 当我使用method = "rpart"时,它工作正常,但当我切换到method = "glm"时,它会给我一个错误说

  

调整参数网格应具有列参数

我尝试使用

cpGrid = data.frame(.0001) 

cpGrid = data.frame(expand.grid(.cp = seq(.0001, .09, .001)))

但两者都抛出错误。
以下是我的初始代码

numFolds = trainControl(method = "cv", number = 10, repeats = 3)
cpGrid = expand.grid(.cp = seq(.0001, .09, .001))

正常

temp <-train(Churn. ~., data = train, method = 'rpart', trControl = numFolds, tuneGrid = cpGrid)

给出错误

treeCV <-train(Churn. ~., data = train, method = 'glm', trControl = numFolds, tuneGrid = data.frame(cpGrid))
predictCV = predict(treeCV, newdata = test, type = "prob")
我的数据中

dput

train <- structure(list(State = structure(c(17L, 32L, 36L, 37L, 20L, 25L
), .Label = c("AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", 
"DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", 
"MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", 
"NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC", 
"SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY"), class = "factor"), 
    VMail.Message = c(25L, 0L, 0L, 0L, 24L, 0L), Day.Mins = c(265.1, 
    243.4, 299.4, 166.7, 218.2, 157), Day.Calls = c(110L, 114L, 
    71L, 113L, 88L, 79L), Eve.Charge = c(16.78, 10.3, 5.26, 12.61, 
    29.62, 8.76), Night.Mins = c(244.7, 162.6, 196.9, 186.9, 
    212.6, 211.8), Night.Calls = c(91L, 104L, 89L, 121L, 118L, 
    96L), Intl.Mins = c(10, 12.2, 6.6, 10.1, 7.5, 7.1), CustServ.Calls = c(1L, 
    0L, 2L, 3L, 3L, 0L), Churn. = structure(c(1L, 1L, 1L, 1L, 
    1L, 1L), .Label = c("False.", "True."), class = "factor"), 
    Area.Code = c(2, 2, 1, 2, 3, 2), Int.l.Plan = c(1, 1, 2, 
    2, 1, 2), VMail.Plan = c(2, 1, 1, 1, 2, 1), Day.Charge = c(565, 
    1005, 1571, 665, 1113, 580), Eve.Mins = c(690, 87, 1535, 
    256, 1517, 9), Eve.Calls = c(120, 12, 109, 25, 10, 115), 
    Night.Charge = c(101, 644, 797, 753, 866, 862), Intl.Calls = c(15, 
    17, 19, 15, 19, 15), Intl.Charge = c(78, 100, 44, 79, 53, 
    49)), .Names = c("State", "VMail.Message", "Day.Mins", "Day.Calls", 
"Eve.Charge", "Night.Mins", "Night.Calls", "Intl.Mins", "CustServ.Calls", 
"Churn.", "Area.Code", "Int.l.Plan", "VMail.Plan", "Day.Charge", 
"Eve.Mins", "Eve.Calls", "Night.Charge", "Intl.Calls", "Intl.Charge"
), row.names = c(1L, 3L, 4L, 5L, 7L, 8L), class = "data.frame")

需要您的帮助才能在cpGrid中使用method = "glm"。还想了解我应该如何在其中加入ntree。我通过这里和那里提供的一些解决方案进行了探索,但似乎没有任何工作。

1 个答案:

答案 0 :(得分:2)

modelLookup中的caret命令提供与模型的调整参数相关的信息 对于rpart,只有一个调整参数可用,cp复杂度参数。

modelLookup("rpart")

#################
  model parameter                label forReg forClass probModel
1 rpart        cp Complexity Parameter   TRUE     TRUE      TRUE

glm的调整参数为parameter(我不知道它的用途):

modelLookup("glm")

#################
  model parameter     label forReg forClass probModel
1   glm parameter parameter   TRUE     TRUE      TRUE

因此,tuneGrid的{​​{1}}需要一个名为glm的列:

.parameter