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

Cannot perform DataFrame operations on generated counterfactuals #388

Open
LakshmanKishore opened this issue Aug 14, 2023 · 2 comments
Open

Comments

@LakshmanKishore
Copy link

I'm using dice-ml - 0.6.1 version. I wanted to perform some DataFrame operations on the generated counterfactuals.
image
Here I have the results of the generated counterfactuals.

image
This is the DataFrame that was generated, and I wanted to replace the target column with the original value (unencoded value), but I failed to replace the value, after some search I found a workaround.

image
This is the way I found by which I can modify the DataFrame and which will affect in the cfs.to_json() method.

In Regression Problem, the counterfactuals generated contained too many decimals which should be rounded, so I used the same way i.e, modifying the final_cfs_df dataframe to round the decimals.

Can we have a method which can perform all the DataFrame operations that directly affects the to_json() method?

@gaugup
Copy link
Collaborator

gaugup commented Sep 6, 2023

@LakshmanKishore, you could save the generated counterfactuals as a .csv file on the disk like following:-

# Save generated counterfactual examples to disk
dice_exp.cf_examples_list[0].final_cfs_df.to_csv(path_or_buf='counterfactuals.csv', index=False)

You could then consume the counterfactuals for whichever query point by reading the .csv file.

import pandas as pd
pd.read_csv('counterfactuals.csv')

Let us know if that can address your concern.

@LakshmanKishore
Copy link
Author

LakshmanKishore commented Sep 7, 2023

This is a workaround that I already have found. As you can see from the screenshots above.
I don't want to save the generated counterfactuals as csv file.

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

2 participants