Skip to content
/ CEILS Public

Counterfactual Explanations as Interventions in Latent Space (CEILS) is a methodology to generate counterfactual explanations capturing by design the underlying causal relations from the data, and at the same time to provide feasible recommendations to reach the proposed profile.

License

Notifications You must be signed in to change notification settings

FLE-ISP/CEILS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

137498084-1adb38cb-0491-44a9-8bf9-b8b326d50496

CEILS

Counterfactual Explanations as Interventions in Latent Space (CEILS) is a methodology to generate counterfactual explanations capturing by design the underlying causal relations from the data, and at the same time to provide feasible recommendations to reach the proposed profile.

Authors & contributors:

Riccardo Crupi, Alessandro Castelnovo, Daniele Regoli, Beatriz San Miguel Gonzalez

You can cite this work as:

@article{crupi2022counterfactual,
  title={Counterfactual explanations as interventions in latent space},
  author={Crupi, Riccardo and Castelnovo, Alessandro and Regoli, Daniele and San Miguel Gonzalez, Beatriz},
  journal={Data Mining and Knowledge Discovery},
  pages={1--37},
  year={2022},
  publisher={Springer}
}

Documentation

To know more about this research work, please refer to our full paper (ArXiv).

Currently, CEILS has been published and/or presented in:

Installation

Create a new environment based on Python 3.9 or 3.6 and install the requirements.

Python 3.9:

pip install -r requirements.txt

Python 3.6:

pip install -r requirements_py36.txt

CEILS Workflow

CEILS workflow consists of the following steps:

drawing

Inputs

Two main inputs are needed:

  • Data. Prepare your dataset as a pandas.DataFrame for the features (X) and a pandas.Series for the target variable (Y)
  • Causal graph. Define your causal relations in a causal graph (G) using networkx.DiGraph.

Moreover, you need to define the features constrains (immutable, higher, lower) as a python dictionary, e.g. constraints_features = {"immutable": ["native-country"], "higher": ["age"]}

Generation of structural equations and the model in the latent space

In the method create_structural_eqs(X, Y, G) from core.build_struct_eq the following steps are carried out:

  • generation of structural equations (F) mapping U to X (F: U->X)
  • computation of residuals (U)
  • generation of original ML model to predict the target variable Y using the features dataset (C: X->Y)
  • composition of the model in the latent space, integrating the previous components (C_causal(U) = C(F(U)))

Summary of the main variables and functions involved:

drawing

Generation of counterfactual explanations

In the method create_counterfactuals(X, Y, G, F, C_causal, constraints_features, numCF=20) from core.counter_causal_generator, two set of counterfactual explanations will be generated based on:

  • CEILS approach: uses the model in the latent space and a general counterfactual generator (Alibi in our current implementation)
  • Baseline approach: uses the original model and the library Alibi

Evaluation

In the method calculate_metrics(X, Y, G, categ_features, constraints_features) from core.metrics, a set of metrics will be computed to compare the two sets of counterfactual explanations. The metrics will be printed.

Experiments

Currenly we have included 3 experiments based on public datasets and 2 experiments with synthetic data:

Experiments are under a specific folder in:

\experiments_run

We recommend to check the run_experiment.py file to know the details and understand the whole CEILS workflow.

Synthetic datasets experiments are the best way to have a first understanding of our solution

About

Counterfactual Explanations as Interventions in Latent Space (CEILS) is a methodology to generate counterfactual explanations capturing by design the underlying causal relations from the data, and at the same time to provide feasible recommendations to reach the proposed profile.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages