gpt4 book ai didi

r - 如何让 R IML FeatureImp() 函数正常工作?

转载 作者:行者123 更新时间:2023-11-30 09:04:50 26 4
gpt4 key购买 nike

我试图从 IML 包中获取 FeatureImp 函数,但它一直抛出错误。下面是来自钻石数据集的示例,我在该示例上训练了随机森林模型。

library(iml)
library(caret)
library(randomForest)
data(diamonds)
# create some binary classification target (without specific meaning)
diamonds$target <- as.factor(ifelse(diamonds$color %in% c("D", "E", "F"), "X", "Y"))
# drop categorical variables (to keep it simple for demonstration purposes)
diamonds <- subset(diamonds, select = -c(color, clarity, cut))
# train model
mdl_diamonds <- train(target ~ ., method = "rf", data = diamonds)
# create iml predictor
x_pred <- Predictor$new(model = mdl_diamonds, data = diamonds[, 1:7], y = diamonds$target, type = "prob")
# calculate feature importance
x_imp <- FeatureImp$new(x_pred, loss = "mae")

最终出现以下错误:

Error in if (self$original.error == 0) { :
missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(actual, predicted) : ‘-’ not meaningful for factors

我不明白我做错了什么。谁能给我线索吗?

我正在开发 R 版本 3.5.1,iml 包版本 0.9.0。

最佳答案

我已经发现问题了。我使用“mae”作为损失函数,这是 - 我可以知道 - 不适用于分类目标。使用“ce”或“f1”会按预期返回输出。

关于r - 如何让 R IML FeatureImp() 函数正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55140970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com