dandls / counterfactuals

counterfactuals: An R package for Counterfactual Explanation Methods
https://dandls.github.io/counterfactuals/
GNU Lesser General Public License v3.0
21 stars 4 forks source link

init_strategy = "icecurve" does not work for ordered factor features #20

Closed dandls closed 1 year ago

dandls commented 2 years ago

Error that new factor level was introduced.

andreash0 commented 1 year ago

Reprex:

library(randomForest)
library(counterfactuals)

df = mtcars
df$cyl = factor(df$cyl, ordered = TRUE)
rf = randomForest(mpg ~ ., data = df)
predictor = iml::Predictor$new(rf)

moc_regr = MOCRegr$new(predictor, n_generations = 15L, quiet = TRUE)
cfactuals = moc_regr$find_counterfactuals(x_interest = df[1L, ], desired_outcome = c(22, 24))
#> Error in predict.randomForest(object, newdata) : New factor levels not present in the training data