interpretml / DiCE

Generate Diverse Counterfactual Explanations for any machine learning model.
https://interpretml.github.io/DiCE/
MIT License
1.35k stars 187 forks source link

Not getting predited_probability for counterfactuals using RandomForest Classifier #232

Open vdesai24 opened 3 years ago

vdesai24 commented 3 years ago

Hi,

I am trying to generate counterfactuals for a classification model. Trained the model using RandomForestClassifier. I am expecting the target variable should show the predicted probability. It is showing predicted class instead. What changes do I need to make to give me the predcited probabilities in the generated counterfactuals. Below is the code to generate counterfactuals: model = RandomForestClassifier() d = dice_ml.Data(dataframe=train_dataset, continuous_features=['age', 'hours_per_week'], outcome_name='income') m = dice_ml.Model(model=model, model_type='classifier',backend="sklearn") exp = dice_ml.Dice(d, m, method="random")

e1 = exp.generate_counterfactuals(x_test[0:1], total_CFs=5, desired_class='opposite') e1.visualize_as_dataframe(show_only_changes=True)

Output: image image

I need predicted probabilities instead of the predicted class in the outcome.

gaugup commented 3 years ago

@vdesai24, the output for the counterfactual is currently only shows the desired_class which is either 0 or 1. We could add another column which can contain the probabilities of the target class in classification scenario.

@amit-sharma what do you think about adding additional column for adding probabilities in classification scenarios?

Regards,

amit-sharma commented 3 years ago

yes, that's a good idea. We just need to call the classifier again on the returned CF data to obtain the predicted probabilities. This would be a general solution that can work for any CF method. For efficiency, we may make it as an optional flag, so that this additional computation is not done.

vdesai24 commented 2 years ago

Hi, Thanks, when can I get this enhancement in the package.

Regards,

amit-sharma commented 2 years ago

We will have to see how to prioritize this change, given the other enhancements we are working on. Hopefully this will be included in the next release, near Dec.

vdesai24 commented 2 years ago

Thanks @amit-sharma

LingAdeu commented 2 months ago

Hi @amit-sharma may I know if this enhancement has been updated? Thanks!