A well-detailed tutorial on how to use this framework to test counterfactual generators can be found in: https://mazzine.medium.com/testing-counterfactual-generation-algorithms-905f5c45fc1c
The example below shows how to run a simple test using all datasets (generating 10 counterfactuals per dataset, total 210).
To run this benchmark to test your counterfactual generation algorithm you will need:
- Ubuntu 18.04
- Anaconda 2020 version or later
Clone this repository using:
git clone The script simple_test.py has the instructions on how you should add your CF generator. Modify it to include your algorithm.
*You may want to copy and paste your code in the same folder *This script includes a dummy counterfactual generator (that only returns the factual instance), so you can run it first to understand more the framework and verify if the prerequisites are met.
There are 6 fields to be modified:
- Your framework name
- Dataset selection to be tested (categorical, numerical, mixed)
- Number of outputs from the neuronal network (1 or 2)
- Initial configuration of the counterfactual generator
- Generation of the counterfactual for the
factualvariable instance - Post-processing of the counterfactual generator result, output of counterfactual candidate
Example to run multiple without terminal message outputs
- A - Starting Row
- B - Ending Row
- C - Name of the benchmark to be run
- D - Dataset to be run (0 to 21)
- E - Class (0 or 1)
cd ./benchmark
sh run_shell_multiple.sh A B C D E &> /dev/nullExample:
cd ./benchmark
sh run_shell_multiple.sh 0 10 benchmark_MLEXPLAIN.py 0 0 &> /dev/nullONLY USE THE SCRIPTS run_full_batch_DS0.sh AND run_full_batch_DS1.sh IN A POWERFUL COMPUTER, THESE SCRIPTS RUN ALL DATASETS IN ONE TIME FOR ONE CLASS
Example:
sh run_full_batch_DS0.sh benchmark_MLEXPLAIN.py &> /dev/nullFor this experiment, the Google Cloud Computing Engine was used with the following specification:
- Series: N1
- Machine Type: Custom
- Cores: 52
- CPU Platform: Intel Skylake or later
- Memory: 195 GB
- OS: Ubuntu 18.04
- Disk: SSD 400 GB
- Series: N2D
- Machine Type: Custom
- Cores: 48
- CPU Platform: AMD Rome or later
- Memory: 384 GB
- OS: Ubuntu 18.04
- Disk: SSD 400 GB
WARNING - THE FOLLOWING STEPS WILL RUN A SCRIPT THAT CONSUMES LOTS OF RESOURCES, SEE THE COMPUTING REQUIREMENTS BEFORE USING
Use as root
sudo suGo to temporary folder
cd /tmpDownload Anaconda 2020.11
curl -O https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-x86_64.shInstall Anaconda
bash Anaconda3-2021.11-Linux-x86_64.shUpdate source
source ~/.bashrcClone this repo
git clone ...Enter repo benchmark folder
cd CounterfactualBenchmark/benchmarkUpdate Ubuntu Package Manager
apt-get updateStart run detached from current terminal (as it takes a long time to run)
nohup bash run_benchmark_full_0_50.sh &> /dev/nullThe next steps are made to guarantee the job will not stop even if the terminal session closes
Press Ctrl+Z to make the process in background
Return process run
bgFind process id (PROCESS_ID)
jobs -lDetach job from terminal session
disown PROCESS_ID