interpretml / DiCE

Generate Diverse Counterfactual Explanations for any machine learning model.
https://interpretml.github.io/DiCE/
MIT License
1.36k stars 188 forks source link

No counterfactuals found! #281

Closed marco-matarese closed 2 years ago

marco-matarese commented 2 years ago

Is it possible to have "No counterfactuals found!" as output of the generate_counterfactual function or am I doing something wrong? I'm using a PyTorch deep neural network to manage an RL agent playing connect 4. I'm following the website instructions so I'm a bit confused because sometimes the explainer isn't able to find me any counterfactual, which is a scenario that I didn't take into account: I thought DiCe'd always generate at least a counterfactual.

amit-sharma commented 2 years ago

It is possible to obtain zero CFs. This depends on the specific algorithm used to find the CFs. It usually means that the algorithm kept searching in the wrong subspace. Changing the parameters and/or the CF algorithm often helps. Also make sure that features_to_vary is set to all

marco-matarese commented 2 years ago

Thank you for your fast reply :) Since I'm using a PyTorch model, I can use only the "random" method (as far as I understood) and I didn't set the features_to_vary parameter so it should be set to "all" by default. With regard to the other parameters, I also tried to change proximity_weight and diversity_weight but I'm not so sure about their value ranges.

amit-sharma commented 2 years ago

Sometimes, it is the neighborhood of the specific point. With the random method, one parameter you can try varying is the sample_size. It is 1000 by default, but setting to a higher value will increase chances of finding a CF.

bruno-hoermann commented 2 years ago

@marco-matarese See my issue (https://github.com/interpretml/DiCE/issues/273). To me it seems that PyTorch and TF backends don't support multiclass prediction (which corresponds to discrete RL). I got the same error as you. I transformed my PyTorch model to a sklearn pipeline which worked with DiCE. Also see their multiclass example notebook.

marco-matarese commented 2 years ago

@bruno-hoermann thank you very much! I have already thought about the solution you're suggesting, but I first wanted to try with no "backend translations".