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

Feature ranges #284

Closed
PaoloFantine opened this issue Apr 5, 2022 · 5 comments
Closed

Feature ranges #284

PaoloFantine opened this issue Apr 5, 2022 · 5 comments

Comments

@PaoloFantine
Copy link

PaoloFantine commented Apr 5, 2022

I am using the drug consumption dataset for a multiclass classification and trying to enforce some permitted ranges like:

d = dice_ml.Data(dataframe = eval_data, 
                 continuous_features = continuous_features, 
                 outcome_name = self.target_name)
        
 m = dice_ml.Model(model = model, backend = backend)
 
 exp = dice_ml.Dice(d, m, method="random")
        
 e1 = exp.generate_counterfactuals(instance = 0,
                   continuous_features = ['nscore', 'escore', 'oscore', 'ascore', 'cscore', 'impulsive', 'ss'],
                   model = model, 
                   backend = "sklearn", 
                   total_CFs = 5,
                   desired_class = 2,
                   features_to_vary = ['nscore', 'escore', 'oscore', 'ascore', 'cscore', 'impulsive', 'ss'],
                   permitted_range = {'oscore':[-1.0, 2.0], 'ascore':[0.0, 0.5], 'cscore':[0.0, 1.0], 'ss':[-2.0, 1.0 ]})

however, I get counterfactuals with values well outside those ranges. I wonder whether this is a bug or, in case there are no available counterfactuals within those ranges, they are somehow overidden?

@gaugup
Copy link
Collaborator

gaugup commented Apr 7, 2022

@PaoloFantine there are no parameters like 'continuous_features', 'instance', 'model', 'backend' in the generate_counterfactuals method. Could you may be use the sample notebooks from https://github.com/interpretml/DiCE/blob/master/docs/source/notebooks/DiCE_getting_started.ipynb to correct the above code?

@PaoloFantine
Copy link
Author

``> @PaoloFantine there are no parameters like 'continuous_features', 'instance', 'model', 'backend' in the generate_counterfactuals method. Could you may be use the sample notebooks from https://github.com/interpretml/DiCE/blob/master/docs/source/notebooks/DiCE_getting_started.ipynb to correct the above code?

That function is a wrapper I use from within a class. My basd for not checking.

e1 = exp.generate_counterfactuals(self.X[instance:instance+1], 
                                          total_CFs = total_CFs, 
                                          desired_class=desired_class,
                                          desired_range=None,
                                          permitted_range=permitted_range,  
                                          features_to_vary=features_to_vary,
                                          stopping_threshold=stopping_threshold, 
                                          posthoc_sparsity_param=posthoc_sparsity_param,
                                          posthoc_sparsity_algorithm=posthoc_sparsity_algorithm,
                                          verbose=False)

where I think you can deduce the parameters from my previous comment. The issue is the same: I get counterfactuals outside the permitted_range and wonder if it is somehow overridden for the sake of finding counterfactuals

@gaugup
Copy link
Collaborator

gaugup commented Apr 7, 2022

We should be respecting the range. If you could share a sample notebook and dataset, it will be possible for us to dig into this issue.

Regards,

@tonyabracadabra
Copy link

We should be respecting the range. If you could share a sample notebook and dataset, it will be possible for us to dig into this issue.

Regards,

apart from the ranges for the continuous variables, how can I set the range for categorical variables? for example I have a categorical variable that contains four categories (A, B, C, D) and I only want the counterfactuals to vary to A, B, C excluding D

@gaugup
Copy link
Collaborator

gaugup commented Apr 20, 2022

@tonyabracadabra, You can do something like this below:-

            exp.generate_counterfactuals(
                query_instances=sample_custom_query_1,
                total_CFs=10,
                desired_class=desired_class,
                desired_range=None,
                permitted_range={'Categorical': ['A', 'B', 'C']},
                features_to_vary='all')

That should be a signal to dice to use only categories 'A', 'B' and 'C' to generate counterfactuals.

Hope this helps.

P.S. Since this question is not related to the original question, we will really appreciate if you opened a new issue for these queries.

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

No branches or pull requests

4 participants