1

I want to create explanator with Dalex of RandomForest model, but when trying I got this error:

Error: $ operator is invalid for atomic vectors

Anyone knows how to solve this issue?

Here my code:

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")

Thanks!

EDIT: I have try with this code

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))

But this do not print the influence of the variables.

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
jff
  • 300
  • 3
  • 14

1 Answers1

1

You can remove model_info or use it as follows:

# 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")

Though when I do this I get a warning message, because y (Species) is a factor. You do not get this warning message if you remove the factor from species, or do not use model_info.

phiver
  • 23,048
  • 14
  • 44
  • 56