-
Notifications
You must be signed in to change notification settings - Fork 252
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
CFRL library generating counterfactual with same label #878
Comments
Thank you for your question! If you are generating counterfactuals for class 1 (i.e., in If you look in the paper, you will see that the objective function is a mixture of divergence loss (i.e., the one that is flipping the class), sparsity loss (i.e., which makes the counterfactul to be close to the original input) and a consistency loss. There might be some difficult cases in which the method will favour sparsity over divergence which will lead to what you've described. That being said, to increase the validity of your counterfactuals I recommend you the followings:
I also recommend using the logging functionalities through callbacks presented at the very end of the notebook. This will give you a much better feeling of how the training evolves and you can actually see how the validity increases during training. There might be other parameters to try if none of the above is working such as action noise ( You can also try to train it without an autoencoder (see example here). If none of the above works, and you really need a counterfactual, then probably the easiest way to get one is to search in your training set an instance that is classified as your intended target and it is close to the input instance w.r.t. some metric of your choice (probably a combination of Although this might not be the case for you, maybe it is worth looking also at this issue - just to avoid an error when computing the validity. Hope this helps. If you still encounter difficulties, please let me know. |
Thanks for your response, I will try to change the configuration. Meanwhile regarding your comment "If none of the above works, and you really need a counterfactual, then probably the easiest way to get one is to search in your training set an instance that is classified as your intended target and it is close to the input instance w.r.t. some metric of your choice (probably a combination of L1 and L0). This should work all the time if you didn't impose any constraints on the feature values of the counterfactual." Any metric that i should look in this case? |
I would suggest you to try the metric proposed in this paper at the bottom of page 5. The metric is as follows:
For categorical features even if you consider a distance equal to 0 if the data points have the same value and 1 otherwise should work fine. I don't think that cosine similarity would be suited for your problem. One reason is that two data points can have a distance of 0 according to the cosine distance, but be perceptually very different. For example the cosine distance between |
I have followed this example : https://docs.seldon.io/projects/alibi/en/stable/examples/cfrl_adult.html
I am generating counterfactual for two class 0 & 1.
But for my example in cell 18 : cf_pd ,which is generated counterfactual has column label which has both 0 & 1 ,Why is it so?If i am generating counterfactual for class 1 than in cf_pd i should be having only class 0 in label column.
Please let me know where i am doing wrong
The text was updated successfully, but these errors were encountered: