1

我想用 RandomForest 模型的 Dalex 创建解释器,但是在尝试时出现此错误:

Error: $ operator is invalid for atomic vectors

任何人都知道如何解决这个问题?

这是我的代码:

library(DALEX)
library(ranger) 
model <- ranger(Species ~ .,data = iris,probability =T,classification = T)
explanation <- explain(model,
                      data=iris,
                      y = iris$Species,
                      model_info = "classification",
                      label="Random Forest")

谢谢!

编辑:我尝试使用此代码

library(DALEX)
library(ranger)
model <- ranger(Species ~ .,iris)
model_info <- list(package = "ranger", ver = "0.12.1", type = "classification")

explanation <- explain(model,
                       data=iris,
                       y = iris$Species,
                      
                       label="Random Forest")


plot(model_profile(explanation))

但这不会打印变量的影响。

4

1 回答 1

1

model_info您可以按如下方式删除或使用它:

# needs to be a list. Not all items are needed. You could just use type.
model_info <- list(package = "ranger", ver = "0.12.1", type = "classification")

explanation <- explain(model,
                      data=iris,
                      y = iris$Species,
                      model_info = model_info,
                      label="Random Forest")

虽然当我这样做时,我会收到一条警告消息,因为 y(物种)是一个因素。如果您从物种中删除该因子,或者不使用 model_info,您不会收到此警告消息。

于 2021-01-15T11:01:50.020 回答