Coder Social home page Coder Social logo

juliatrustworthyai / algorithmicrecoursedynamics.jl Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 0.0 219.32 MB

A Julia package for modelling Algorithmic Recourse Dynamics.

Home Page: http://juliatrustworthyai.github.io/AlgorithmicRecourseDynamics.jl/

License: MIT License

TeX 67.72% Julia 32.28%
algorithmic-recourse counterfactual-explanations explainable-ai

algorithmicrecoursedynamics.jl's Introduction

Stable Dev Build Status Coverage Code Style: Blue ColPrac: Contributor’s Guide on Collaborative Practices for Community Packages Twitter Badge

AlgorithmicRecourseDynamics

AlgorithmicRecourseDynamics.jl is a small package for modeling Algorithmic Recourse Dynamics. It builds on CounterfactualExplanations, a package for generating counterfactual explanations.

Basic Usage

Below we first generate some synthetic data for a binary classification task and instantiate an instance of CounterfactualData.

N = 1000
xmax = 2
X, ys = make_blobs(
    N, 2; 
    centers=2, as_table=false, center_box=(-xmax => xmax), cluster_std=0.1
)
ys .= ys.==2
X = X'
counterfactual_data = CounterfactualData(X,ys')

We then define a simple model for the task and prepare it for use with CounterfactualExplanations.jl:

n_epochs = 100
model = Chain(Dense(2,1))
mod = FluxModel(model)

To generate algorithmic recourse, we will use a simple generic generator:

generator = GenericGenerator()

Finally we train our model on a subset of the data. The chart below shows the results.

data_train, data_test = Data.train_test_split(counterfactual_data)
CounterfactualExplanations.Models.train(mod, data_train; n_epochs=n_epochs)
plt_original = plot(mod, counterfactual_data; zoom=0, colorbar=false)
display(plt_original)

Simulation

To model the dynamics of algorithmic recourse, we use simulations, in which we repeatedly select as subset of individuals from the non-target class, generate and implement recourse for all of them and finally retrain the model. To set this experiment up, we can use the code below:

models = Dict(:mymodel => mod)
generators = Dict(:wachter => generator)
experiment = set_up_experiment(data_train, data_test, models, generators)

Finally, we just run the experiment using default parameter settings that specify the number of rounds, the proportion of individuals to select for recourse and related aspects:

run!(experiment)

The chart below shows the data and predictions at the end of the simulation:

new_data = experiment.recourse_systems[1][1].data
new_model = experiment.recourse_systems[1][1].model
plt_original = plot(new_model, new_data; zoom=0, colorbar=false)

Related Research Paper 📝

The package was developed for a research project that investigates the dynamics of various counterfactual generators. You can find the details here.

algorithmicrecoursedynamics.jl's People

Contributors

informusica avatar pat-alt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

algorithmicrecoursedynamics.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.