alexforel / RobustCF4RF

Code for "Robust counterfactual explanations for random forests"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Robust Counterfactual Explanations for Random Forests

This code can be used to reproduce all figures and results in the manuscript titled "Robust Counterfactual Explanations for Random Forests" available at: https://arxiv.org/abs/2205.14116.

Installation

The project requires the Gurobi solver to be installed with an authorized license. Free academic licenses can be obtained at: https://www.gurobi.com/academia/academic-program-and-licenses/ .

The packages required are listed in the file environment.yml. A virtual python environment can be created using an Anaconda Distribution (https://www.anaconda.com/products/distribution) by using: conda env create -f environment.yml in the project root directory. This will automatically install all required packages and their dependencies.

Content

The main scripts that generate data or results are included in the root folder. The folders have the following contents:

  • datasets: the raw data sets in .csv files,
  • ocean: a copy of the OCEAN package taken from https://github.com/vidalt/OCEAN that has been adapted,
  • src: all local functions needed to generate and analyze the experimental results.

How to reproduce the paper results

All experiments are run using the script run_robust_counterfactuals.py. The results are stored in the folder output\robustTrainingCounterfactuals. The experiments take around 24 hours to compute.

Some figures can be generated directly from python scripts:

  • Figures 2, 7 and 8: can be generated directly by running illustrate_robust_cf_trajectory.py,
  • Figures 4, 6, 9, and 10: can be generated directly by running illustrate_feature_importance_and_robustness.py.

The remaining figures are created in LaTeX using .csv files stored in the output folder. The files are obtained by running the following scripts:

  • Figure 1: the data is generated by running illustrate_p_star_b_alpha.py,
  • Figures 3, 5, and 11: the data is generated by running analyze_robust_counterfactuals.py.

About

Code for "Robust counterfactual explanations for random forests"

License:MIT License


Languages

Language:Python 100.0%