Issues with tuneGrid parameter in random forest

ぐ巨炮叔叔 提交于 2019-12-03 07:14:26

It looks like there is a bracket issue with your mtryGrid. Alternatively, you can also use expand.grid to give the different values of mtry you want to try. By default the only parameter you can tune for a random forest is mtry. However you can still pass the others parameters to train. But those will have a fix value an so won't be tuned by train. But you can still ask to use a stratified sample in train. Below is how I would do, assuming that trainY is a boolean variable according which you want to stratify your samples, and that you want samples of size 80 for each category:

mtryGrid <- expand.grid(mtry = 100) # you can put different values for mtry
rfTune<- train(x = trainX,
               y = trainY,
               method = "rf",
               trControl = ctrl,
               metric = "Kappa",
               ntree = 1000,
               tuneGrid = mtryGrid,
               strata = factor(trainY),
               sampsize = c(80, 80), 
               importance = TRUE)

I doubt one can directly pass sampsize and strata to train. But from here I believe the solution is to use trControl(). That is,

mtryGrid <- data.frame(.mtry = 100),.sampsize=80)
rfTune<- train(x = trainX,
               y = trainY,
               method = "rf",
               trControl = trainControl(sampling=X),
               metric = "Kappa",
               ntree = 1000,
               tuneGrid = mtryGrid,
               importance = TRUE)

where X can be one of c("up","down","smote","rose").

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!