DiCE
DiCE copied to clipboard
Desired output is 1 and query is the one which has the original output 0. How to select such queries?
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.
- 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?
- 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!