feat: Add support for CFRL (and dataset/dependency fixes)#36
Merged
zkhotanlou merged 19 commits intocharmlab:mainfrom Nov 23, 2025
Merged
feat: Add support for CFRL (and dataset/dependency fixes)#36zkhotanlou merged 19 commits intocharmlab:mainfrom
zkhotanlou merged 19 commits intocharmlab:mainfrom
Conversation
… from alibi documents
…1.2 (triggered by pytest)
zkhotanlou
reviewed
Nov 21, 2025
Collaborator
zkhotanlou
left a comment
There was a problem hiding this comment.
Thank you for this complete implementation and the helpful fixing issues. Just please address the minor comments remaining, otherwise it's ready to merge.
Collaborator
|
This is an implementation of the "CFRL"[1] recourse method. The level of reproduction is on level1 as the unit tests check the implementation could reproduce the results reported in the paper for Random Forest on Adult dataset. [1] Samoilescu, R. F., Van Looveren, A., & Klaise, J. (2021). Model-agnostic and scalable counterfactual explanations via reinforcement learning. arXiv preprint arXiv:2106.02597. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for CFRL
Reproducibility
Level-1 reproducibility is achieved with this implementation (Random Forest on Adult), and I'm personally confident about raising it to level-2 (by adding more target models).
Implementation
This implementation is largely based on Sheldon.IO's official repo alibi, especially the RL Agent part, which locates in
cfrl_*.pyHowever, Autoencoder (based on Adult AE in the paper) part (based on Adult AE in the paper) is mostly done from scratch, which locates inmodel.py. The authors didn't provide seeds.Here are the details:
model.py-> _ordered_to_cfrl() and _cfrl_to_ordered(). It will convert onehot+normalized data to raw data (and back). It will read metadata by running loadDataset() again (since metadata is dropped by DataCatalog). An unit test / visualizer which supports bothpython -m pytest methods/catalog/cfrl/dataset_adaptor_test.py(unit test) andpython -m methods.catalog.cfrl.dataset_adaptor_test(visualize) is provided. Welcome to test it on different datasets and transplant it to other methods that requires raw data / metadata.Fixes
This PR also does some general fixes for the framework's base components.
loadData.pywas moved from/datato/data/catalog. Old cached onehot dataset pickles embedded the path of/data/loadData.py, which is not true anymore, so if it try to load a dataset using that pickle, it will fall back to load the raw data, which is not in/dataanymore either (in/data/raw_datanow). Then failure occurs and stoprun_experiments.py. With this PR, all affected dataset loading scripts (adult, compass, credit) are fixed and all cached dataset pickles are updated.run_experiments.py's comments and default cli args are now more consistent. It will by default run all supported methods, avoiding unexpected behaviours.setup.py(install as a package) andrequirements-dev.txt(manually install) more consistent.Trivials
run_experiments.py's default) and run credit dataset only with linear classifier, the classifier will predict all 1, so there's no negative case for recourse, then credit will be jumped (the current design will only do 0->1 flip). It's possibly the reason whyrun_experiments.pyis jumping datasets. Although by re-running, it will possibly act normally, this "normal" behaviour can disturb experiment immutability. (Pseudo random numbers varies to the generation order, even when random seed is fixed.)