How can I get the index of counterfactuals?
Hi. Thank you for great package for Interpret. Here's my question. How can I get the index of counterfactuals?
ebm = ExplainableBoostingClassifier(interactions=0) ebm.fit(X_train[:10000], y_train[:10000])
d = dice_ml.Data(dataframe=df_train.iloc[:10000,1:],continuous_features=X_train.columns.tolist(), outcome_name='target') m = dice_ml.Model(model=ebm, backend='sklearn') exp = dice_ml.Dice(d,m)
e1 = exp.generate_counterfactuals(X_train[0:1], total_CFs=10, desired_class="opposite") e1.visualize_as_dataframe(show_only_changes=True)
After "visualize_as_dataframe", It returns dataframe for instance and counterfactuals. But I have no idea what instance is counterfactuals.
Thank you for you help in advanced.
@Jihyun-Yun-0110 If I understand your question correctly, you are asking for the index of the generated counterfactuals in the dataset.
The default method for generate_counterfactuals looks for the closest point that yields a different predicted class. This point need not be in the dataset. It is a simulated point that helps to understand the model's decision boundary, and therefore there is no corresponding index in the dataset.
That said, there is a method kd-tree that does output the closest point in the dataset. @soundarya98 is there a way to retrieve the index of those points in the original dataset?
@amit-sharma Thank you for your kind reply. I tried a method kd-tree, but I still want to get dataframe or array or index for the counterfactuals found.
Dear @jh-0110, Thanks for raising the issue. We will address your issue in a new pull request coming shortly which will give the original indices of the counterfactuals found using `kd-tree'.
Thank you very much @amit-sharma , @soundarya98 :)