【问题标题】:ALEPlots for categorical variables in classification model in RR中分类模型中分类变量的ALEPlots
【发布时间】: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


    【解决方案1】:

    我无法重现该错误。当我测试它时,代码运行并生成了 ALE 图。 (顺便说一句。脚本中有错字,应该是 low_predictor,而不是 Low_predictor)。

    确保在新的 R 会话中启动代码。您是否安装了最新版本的 iml? 如果您可以共享整个输出,它也可能会有所帮助。

    你得到什么输出 FeatureEffect$new(Low_predictor, feature = "veg", method = "ale")$results?

    【讨论】:

    • 如果我遵循该脚本,则会收到此错误“(1 - h) * qs[i] 中的错误:二进制运算符的非数字参数”。 iml 包是最新的。
    • 我更新了我的帖子以包含一个可重复的样本
    猜你喜欢
    • 2015-07-21
    • 1970-01-01
    • 2018-05-04
    • 2022-01-14
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    相关资源
    最近更新 更多