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

Desired output is 1 and query is the one which has the original output 0. How to select such queries? #430

Open
asha24choudhary opened this issue Feb 20, 2024 · 0 comments

Comments

@asha24choudhary
Copy link

Hi @amit-sharma,

I am trying to generate counterfactuals using the following code

##data 
train_dataset, test_dataset, y_train, y_test = train_test_split(df1, y, test_size=0.2, random_state=42, stratify = y) #train test split
X_train = train_dataset.drop('output_lag0', axis=1)
X_test = test_dataset.drop('output_lag0', axis=1)

#model training
model = LogisticRegression(max_iter=500)
model.fit(X_train, y_train)


##Counterfactual generation
d = dice_ml.Data(dataframe=train_dataset, continuous_features=list(df1.columns.difference(['output_lag0','output_lag1'])), 
                 outcome_name='output_lag0')
m = dice_ml.Model(model=model, backend="sklearn")
exp = dice_ml.Dice(d, m, method="random")
e = exp.generate_counterfactuals(X_test.loc[[57]], total_CFs=5, desired_class='opposite')
e.visualize_as_dataframe(show_only_changes=True)

I have two questions for you.

  1. Here when I give a query to the model, it assumes that my original outcome is 1, which is 0 if I compare it with y_test and then it generates CF accordingly. Am I doing something wrong here?
  2. I want to figure out how can I get counterfactuals when the original output was 0 and the desired output is 1. I mean I want to know what should I do so that the output changes to 1 from 0. Could you please help?

Thank you in advance!

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

1 participant