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

$plot_parallel() fails with an ugly error message if there are no numeric features #22

Closed andreash0 closed 1 year ago

andreash0 commented 1 year ago

Reprex:

library(mlr3oml)
library(counterfactuals)
oml_data = OMLData$new(50)
tic_tac_toe <- oml_data$data
rf = randomForest::randomForest(Class ~ ., data = tic_tac_toe)
predictor = iml::Predictor$new(rf)
whatif_classif = WhatIfClassif$new(predictor, n_counterfactuals = 10L)
cfactuals = whatif_classif$find_counterfactuals(
  x_interest = tic_tac_toe[1L, ], desired_class = "negative", desired_prob = c(0.5, 1)
)
cfactuals$plot_parallel()
#> Warning in cfactuals$plot_parallel(): Can only consider numeric features for
#> parallel plot. Non-numeric features have been removed.
#> Error in `$<-.data.frame`(`*tmp*`, ".ID", value = structure(2:1, .Label = c("0", : Ersetzung hat 2 Zeilen, Daten haben 0

TODO: Add check, if there are any numeric features and exit early if not.