Counterfactuals API for Weka

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Counterfactuals API for Weka

kumarbojanki
Hello All,
I am trying to implement Java code for  Counterfactuals functionality for classification algorithms using Weka API. I am unable to find any API for this algorithm in weka wiki page. Could you please help me with this by providing any info of the API in weka wiki or any reference where it is already implemented or how to implement this using weka. It would be very helpful to continue my work.

Below is an explanation of python code implementation of Counterfactual.
https://docs.seldon.io/projects/alibi/en/latest/methods/CF.html
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
Reply | Threaded
Open this post in threaded view
|

Re: Counterfactuals API for Weka

bojankikumar
Hello All,
Could you please consider this as a gentle reminder.
Even if there is no API could you provide suggestions on how to implement this using weka, as this would be very helpful.

I tried to understand the implementation https://christophm.github.io/interpretable-ml-book/counterfactual.html

https://github.com/SeldonIO/alibi/blob/524d786c81735ed90da2d2c68851c1145fa1b595/doc/source/methods/CF.ipynb

Like in the above links to implement this they have given some suggestions and steps to follow. But which functions and classes should i call or use from weka to implement them ?

" The function d for measuring the distance between instance x and counterfactual x’ is the Manhattan distance weighted feature-wise with the inverse median absolute deviation (MAD). "

"To minimize this loss function, any suitable optimization algorithm can be used, e.g. Nelder-Mead. If you have access to the gradients of the machine learning model, you can use gradient-based methods like ADAM"

The recipe for producing the counterfactuals is simple:

1) Select an instance x to be explained, the desired outcome y’, a tolerance  ϵ
  and a (low) initial value for   λ.
2) Sample a random instance as initial counterfactual.
3) Optimize the loss with the initially sampled counterfactual as starting point.
4) While  
|^f(x′)−y′|>ϵ:Increase  λ .
Optimize the loss with the current counterfactual as starting point.
Return the counterfactual that minimizes the loss.
5)Repeat steps 2-4 and return the list of counterfactual or the one that minimizes the loss.
_______________________________________________
Wekalist mailing list -- [hidden email]
Send posts to [hidden email]
To unsubscribe send an email to [hidden email]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html