[英]Error with “partial” function in pdp package when using random forest
I am getting an error message when using the partial
function from the pdp
package on my random forest model. 在随机森林模型上使用pdp
包中的partial
函数时,出现错误消息。 I am trying to plot a partial dependence plot using this package. 我正在尝试使用此包绘制部分依赖图。
library(randomForest)
library(pdp)
# random forest model
set.seed(101)
model_rf <- randomForest(Rec ~ ., data = sample, importance = TRUE)
# from pdp package
p1 <- partial(model_rf, pred.var = "HDI", plot = TRUE)
Then I get this error when running into the last line: 然后我遇到最后一行时出现此错误:
Error:
.f
must be a function, not aarandomForest.formula/randomForest
object 错误:.f
必须是一个函数,而不是randomForest.formula/randomForest
对象
I'm not sure what .f
its referring to and I have found the exact same code online where this partial
function works using a random forest model. 我不确定它指的是什么.f
,并且我在网上找到了完全相同的代码,其中该partial
函数使用随机森林模型运行。
The same problem bothered me as well. 同样的问题也困扰着我。 I will post the solution here, so that people can learn from my mistake. 我将在此处发布解决方案,以便人们可以从我的错误中学习。
I had the same error when using pdp because I also loaded the dplyr package, which resulted in pdp::partial being blocked due to name conflict. 使用pdp时出现相同的错误,因为我还加载了dplyr包,这导致pdp :: partial由于名称冲突而被阻止。 Check the conflicts and detach the package with "conflicting interest", then it should be all good. 检查冲突并以“有利益冲突”的方式拆开包装,那么一切都应该很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.