DiCE icon indicating copy to clipboard operation
DiCE copied to clipboard

Not getting predited_probability for counterfactuals using RandomForest Classifier

Open vdesai24 opened this issue 4 years ago • 6 comments

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.

vdesai24 avatar Sep 20 '21 07:09 vdesai24

@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,

gaugup avatar Sep 21 '21 05:09 gaugup

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.

amit-sharma avatar Oct 10 '21 11:10 amit-sharma

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

Regards,

vdesai24 avatar Oct 21 '21 06:10 vdesai24

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.

amit-sharma avatar Oct 21 '21 06:10 amit-sharma

Thanks @amit-sharma

vdesai24 avatar Oct 21 '21 18:10 vdesai24