interpretml / DiCE

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

Issue in use case: CounterFactual Explanation without accessing training data #177

Open msank00 opened 3 years ago

msank00 commented 3 years ago

Hi Team,

Thanks for providing such an useful package.

Now following this tutorial notebook, I am trying to generate CounterFactual Explanation without accessing training data.

My Data generation process is something like this

private_d = dice_ml.data.Data(features={
                   'Gender':[0, 1], # male = 1, female = 0
                   'Age': [15, 100],
                   'Driving_License': [0, 1], # yes = 1, no = 0
                   'Region_Code': [0, 52],
                   'Previously_Insured':[0, 1], # yes = 1, no = 0
                   'Vehicle_Age': [0, 1, 2], # "1-2 year" = 0, "< 1 yr" = 1, ">2 yr" = 2
                   'Vehicle_Damage':[0, 1], # yes = 1, no = 0
                   'Annual_Premium': [2500, 50000],
                   'Policy_Sales_Channel' :[0, 132],
                   'Vintage': [10, 299]
                },
         outcome_name='Response')

Next I tried to create the explainer

# Using method=random for generating CFs
private_exp = dice_ml.Dice(private_d, m, method="random")

But getting following error

TypeError                                 Traceback (most recent call last)
<ipython-input-41-b89e02dd96ed> in <module>
      1 # Using method=random for generating CFs
----> 2 private_exp = dice_ml.Dice(private_d, m, method="random")

~/miniconda3/envs/respai/lib/python3.8/site-packages/dice_ml/dice.py in __init__(self, data_interface, model_interface, method, **kwargs)
     17         :param method: Name of the method to use for generating counterfactuals
     18         """
---> 19         self.decide_implementation_type(data_interface, model_interface, method, **kwargs)
     20 
     21     def decide_implementation_type(self, data_interface, model_interface, method, **kwargs):

~/miniconda3/envs/respai/lib/python3.8/site-packages/dice_ml/dice.py in decide_implementation_type(self, data_interface, model_interface, method, **kwargs)
     22         """Decides DiCE implementation type."""
     23         self.__class__ = decide(model_interface, method)
---> 24         self.__init__(data_interface, model_interface, **kwargs)
     25 
     26 

~/miniconda3/envs/respai/lib/python3.8/site-packages/dice_ml/explainer_interfaces/dice_random.py in __init__(self, data_interface, model_interface)
     29         self.model.transformer.initialize_transform_func()
     30 
---> 31         self.precisions = self.data_interface.get_decimal_precisions(output_type="dict")
     32         if self.data_interface.outcome_name in self.precisions:
     33             self.outcome_precision = [self.precisions[self.data_interface.outcome_name]]

TypeError: get_decimal_precisions() got an unexpected keyword argument 'output_type'

Could you please guide me where it's getting wrong? Why the error is showing up?

Thanks in advance.

gaugup commented 3 years ago

@msank00, sorry that you are facing this issue. There seems to be a bug in dice_random.py and it may not work with private dataset. I will have a PR out shortly to fix this.

Could you maybe in meantime try with method="genetic"/"kdtree"? From looking at the code, these should work.

Using method=genetic for generating CFs

private_exp = dice_ml.Dice(private_d, m, method="genetic")

gaugup commented 3 years ago

@amit-sharma, does the dice-ml private data interface work with dice_random.py, dice_genetic.py and dice_kd_tree.py? Or is this scenario not supported as of now?

amit-sharma commented 3 years ago

This scenario is not supported as of now. Can look to implement it for dice_random and dice_genetic.

Dice_kd does require access to the dataset so it will not work. Perhaps we can add a clear exception for this.

gaugup commented 3 years ago

Thanks for confirming @amit-sharma. I created a milestone https://github.com/interpretml/DiCE/milestone/2 and added the issue to that.