0
我正在嘗試在train
中使用method = "glm"
建立分類模型。 當我使用method = "rpart"
它工作正常,但是當我切換到method = "glm"
然後它給了我一個錯誤說「glm」與「rf」中的調整參數
調諧參數電網應該有列參數
我嘗試使用
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")
需要您的幫助,在method = "glm"
中使用cpGrid
也想知道我應該如何在此包含ntree
。我通過一些在這裏和那裏提供的解決方案進行了探索,但似乎沒有任何工作。
「glm」沒有調整參數https://stackoverflow.com/questions/47822694/logistic-regression-tuning-parameter-grid-in-r-caret-package/48218280#48218280 – jmuhlenkamp