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

TypeError: _generate_counterfactuals() got an unexpected keyword argument 'feature_weights' #406

Open
Siki-cloud opened this issue Sep 20, 2023 · 3 comments

Comments

@Siki-cloud
Copy link

When running the below code in DICE_with_advanced_option.ipynb, it dumps due to the the below error:
code:

generate counterfactuals

dice_exp = exp.generate_counterfactuals(query_instance, total_CFs=4, desired_class="opposite",
feature_weights=feature_weights)

error:
TypeError Traceback (most recent call last)
Cell In[18], line 2
1 # generate counterfactuals
----> 2 dice_exp = exp.generate_counterfactuals(query_instance, total_CFs=4, desired_class="opposite",
3 feature_weights=feature_weights)

..\dice_ml\explainer_interfaces\explainer_base.py:161, in ExplainerBase.generate_counterfactuals(self, query_instances, total_CFs, desired_class, desired_range, permitted_range, features_to_vary, stopping_threshold, posthoc_sparsity_param, proximity_weight, sparsity_weight, diversity_weight, categorical_penalty, posthoc_sparsity_algorithm, verbose, **kwargs)
159 for query_instance in tqdm(query_instances_list):
160 self.data_interface.set_continuous_feature_indexes(query_instance)
--> 161 res = self._generate_counterfactuals(
162 query_instance, total_CFs,
163 desired_class=desired_class,
164 desired_range=desired_range,
165 permitted_range=permitted_range,
166 features_to_vary=features_to_vary,
167 stopping_threshold=stopping_threshold,
168 posthoc_sparsity_param=posthoc_sparsity_param,
169 posthoc_sparsity_algorithm=posthoc_sparsity_algorithm,
170 verbose=verbose,
171 **kwargs)
172 cf_examples_arr.append(res)
173 self._check_any_counterfactuals_computed(cf_examples_arr=cf_examples_arr)

TypeError: _generate_counterfactuals() got an unexpected keyword argument 'feature_weights'

@gaugup
Copy link
Collaborator

gaugup commented Sep 20, 2023

@Siki-cloud The API generate_counterfacutals() doesn't support feature_weights

def generate_counterfactuals(self, query_instances, total_CFs,
. Is this issue a feature request?

@Siki-cloud
Copy link
Author

@Siki-cloud The API generate_counterfacutals() doesn't support feature_weights

def generate_counterfactuals(self, query_instances, total_CFs,

. Is this issue a feature request?

I noticed that DiceRandom encounters errors, but is feature_weight not required for random-based? That's my understanding. However, for gradient-based methods, there is a custom feature_weight functionality implemented, which should be sufficient. Thank you.

@gustavo-rddi
Copy link

I encountered this issue too. The confusion is that this page in the documentation states that the user can pass a parameter called feature_weights, which is a dictionary with weights for each feature. However, as pointed out, this is not actually implemented in generate_counterfactuals.
Instead, that method supports other 'weight' parameters: proximity_weight, sparsity_weight, diversity_weight; however, these parameters expect a positive float, meaning that the user cannot specify a different value for each feature. Furthermore, beyond the docstring, the documentation does not explain what their effect is, and it says they are ignored when using the 'random' and 'kdtree' methods.

I would like to have a way to specify that some features are harder to change than others, just as explained in the text on this page. I'm using sklearn pre-trained pipelines, so I cannot use gradient-based methods. How could I achieve this in the current implementation? Please advise. Thanks!

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

3 participants