使用插入符号的train函数的FinalModel输出为RF建立部分依赖图时出错

问题描述

我正在使用以下代码来拟合和测试随机森林分类模型:

> control <- trainControl(method='repeatedcv',+                         number=5,repeats = 3,+                         search='grid') 
> tunegrid <- expand.grid(.mtry = (1:12)) 
> rf_gridsearch <- train(y = river$stat_bino,+                        x = river[,colnames(river) != "stat_bino"],+                              data = river,+                              method = 'rf',+                              metric = 'Accuracy',+                              ntree = 600,+                              importance = TRUE,+                              tuneGrid = tunegrid,trControl = control)  

注意,我正在使用

train(y = river$stat_bino,x = river[,...
rather than: train(stat_bino ~ .,... 

,这样我的分类变量就不会变成虚拟变量。 解决方在这里variable encoding in K-fold validation of random forest using package 'caret'

我想提取FinalModel并将其用于为变量创建部分依赖图(使用下面的代码),但是我收到一条错误消息,并且不知道如何解决

> model1 <- rf_gridsearch$finalModel
> library(pdp)
> partial(model1,pred.var = "MAXCL",type = "classification",which.class = "1",plot =TRUE)
Error in eval(stats::getCall(object)$data) : 
  ..1 used in an incorrect context,no ... to look in

感谢您在此处提供任何解决方案!

解决方法

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

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

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