【发布时间】:2021-11-06 10:46:29
【问题描述】:
我正在尝试为分类随机森林模型中的分类变量创建 ALE 图。我的 ALE 绘图代码适用于连续变量:
#packages
library(randomForest)
library(ALEPlot)
library(iml)
# create sample data frame
data <- data.frame(mortality = as.factor(c(rep("Low", 200), rep("High", 200))),
veg = as.factor(rep(c("Shrub", "Oak", "conifer", "forb"), each = 50)),
slope = rep(seq(0,90), length = 200))
# random forest model
rfm <- randomForest(mortality ~., data = data)
# ALE plot
low_predictor <- Predictor$new(rfm, data = data, type = "prob", class="Low")
high_predictor <- Predictor$new(rfm, data = data, type = "prob", class="High")
## Vegetation variable
low_veg <- plot(FeatureEffect$new(Low_predictor, feature = "veg", method = "ale"))
high_veg <- plot(FeatureEffect$new(high_predictor, feature = "veg", method = "ale"))
plot(low_veg)
plot(high_veg)
## slope variable
low_slope <- plot(FeatureEffect$new(Low_predictor, feature = "slope", method = "ale"))
high_slope <- plot(FeatureEffect$new(high_predictor, feature = "slope", method = "ale"))
plot(low_slope)
plot(high_slope)
我得到错误:
"h(simpleError(msg, call)) 中的错误:评估参数时出错 'x' 在为函数'plot' 选择方法时:非数字参数 二元运算符"
响应变量是二元的,分类变量有 4 个类别。
如果我将方法从“ale”更改为“pdp”,代码也可以工作,但只是在我尝试制作 ale 情节时不行。有没有其他人遇到过这个问题?也许无法为我正在尝试做的事情创建啤酒图?
【问题讨论】:
标签: r machine-learning random-forest