Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CounterfactualMethod printer broken? #37

Closed
mb706 opened this issue Apr 22, 2024 · 2 comments · Fixed by #39
Closed

CounterfactualMethod printer broken? #37

mb706 opened this issue Apr 22, 2024 · 2 comments · Fixed by #39

Comments

@mb706
Copy link
Collaborator

mb706 commented Apr 22, 2024

Following the steps from the intro vignette, but then printing the "CounterfactualMethod" object:

data(german, package = "rchallenge")
credit = german[, c("duration", "amount", "purpose", "age", "employment_duration", "housing", "number_credits", "credit_risk")]

set.seed(20210816)
rf = randomForest::randomForest(credit_risk ~ ., data = credit[-998L,])

predictor = iml::Predictor$new(rf, type = "prob")
x_interest = credit[998L, ]

moc_classif = MOCClassif$new(
  predictor, epsilon = 0, fixed_features = c("age", "employment_duration"),
  quiet = TRUE, termination_crit = "genstag", n_generations = 10L
)

moc_classif

gives the output

Counterfactual explanation method:  MOCClassif 
Parameters:
 - epsilon:  0 
 - fixed_features:  age employment_duration 
 - init_strategy:  icecurve 
 - k:  1 
 - lower:  
 - max_changed:  
 - mu:  20 
 - termination_crit:  genstag 
 - n_generations:  10 
 - p_mut:  0.73 
 - p_mut_gen:  0.5 
 - p_mut_use_orig:  0.4 
 - p_rec:  0.71 
 - p_rec_gen:  0.62 
 - upper:  - weights:  
  • the -upper: - weights: looks unintentional
  • one could also put lower and upper right next to each other
  • are empty entries like lower: and max_changed: deliberate?
@andreash0
Copy link
Collaborator

Hi @mb706, thanks for the observations!

Regarding your points:

  • the -upper: - weights: looks unintentional -> True, I will fix that
  • one could also put lower and upper right next to each other -> True, I will implement that
  • are empty entries like lower: and max_changed: deliberate? -> The empty entries are due to NULL values. Would you fix this with a wrapper like the following or are you aware of a better method?
null_to_char <- function(x) {
  if (is.null(x)) {
    cat("NULL")
  } else {
    cat(x)
  }
}

@mb706
Copy link
Collaborator Author

mb706 commented May 8, 2024

If the value is only ever a scalar or NULL you can also do cat(x %??% "NULL"), using %??% from checkmate.

I don't think you need a helper function here, but if you want to implement one, I would not write a function that outputs a value (using cat), but instead just converts to a string, e.g. to_string <- function(x) x %??% "NULL". It could also do other things, like paste(x, collapse = ", "), if it should be necessary somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants